Giter Site home page Giter Site logo

bbc / lrud Goto Github PK

View Code? Open in Web Editor NEW
90.0 55.0 21.0 8.53 MB

Left, Right, Up, Down. A spatial navigation library for devices with input via directional controls.

License: Apache License 2.0

JavaScript 79.09% TypeScript 20.91%
spatial-navigation-library lrud bbc tv tv-navigation remote-control tv-remote-control

lrud's Introduction

LRUD Build Status

A spatial navigation library for devices with input via directional controls

๐Ÿ”ฉ Maintenance Mode ๐Ÿ”ฉ

LRUD is now in maintenance mode; existing bugs will be fixed, but new features will not be added. A new library called LRUD Spatial is now available to the Open Source community.

Upgrading from V2

v3 is a major rewrite, covering many new features. However, it unfortunately breaks some backwards compatibility.

We are currently in the process of writing more detailed docs for an upgrade process. However, the main things to note at the minute at;

  • changes in events, which ones are emitted and what they are emitted with
  • removal of grid in favour of isIndexAligned behaviour

Getting Started

git clone [email protected]:bbc/lrud.git lrud
cd lrud
npm install

Lrud is written in Typescript and makes use of mitt.

Usage

npm install lrud
const { Lrud } = require('Lrud')

// create an instance, register some nodes and assign a default focus
var navigation = new Lrud()
navigation
  .registerNode('root', { orientation: 'vertical' })
  .registerNode('item-a', { parent: 'root', isFocusable: true })
  .registerNode('item-b', { parent: 'root', isFocusable: true })
  .assignFocus('item-a')

// handle a key event
document.addEventListener('keypress', (event) => {
  navigation.handleKeyEvent(event)
});

// Lrud will output an event when it handles a move
navigation.on('move', (moveEvent) => {
  myApp.doSomethingOnNodeFocus(moveEvent.enter)
})

See usage docs for details full API details.

For more "full" examples, covering common use cases, check the recipes

Running the tests

All code is written in Typescript, so we make use of a tsconfig.json and jest.config.js to ensure tests run correctly.

Test files are split up fairly arbitrarily, aiming to have larger sets of tests broken into their own file.

npm test

To run a specific test file, use npx jest from the project root.

npx jest src/lrud.test.js

You can also run all the tests with verbose output. This is useful for listing out test scenarios to ensure that behaviour is covered.

npm run test:verbose

You can also run all the tests with coverage output

npm run test:coverage

Several of the tests have associated diagrams, in order to better explain what is being tested. These can be found in ./docs/test-diagrams.

We also have a specific test file (src/build.test.js) in order to ensure that we haven't broken the Typescript/rollup.js build.

Versioning

npm version <patch:minor:major>
npm publish

Built with

Inspiration

Alternatives

License

LRUD is part of the BBC TAL libraries, and available to everyone under the terms of the Apache 2 open source licence (Apache-2.0). Take a look at the LICENSE file in the code.

Copyright (c) 2018 BBC

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.