Giter Site home page Giter Site logo

Support cancellation of movement about lrud HOT 5 CLOSED

bbc avatar bbc commented on May 28, 2024
Support cancellation of movement

from lrud.

Comments (5)

thomascgray avatar thomascgray commented on May 28, 2024 2

Thanks for raising the issue @do0g , and for the chat earlier!

To continue from what Jordan said, some initial thoughts...

During the actual process of handling a movement, before the assignFocus() is called (thus "completing the movement") we provide an opportunity for a callback to fire.

If said callback returns true, instead of assigning the focus and firing the focus and move events, we fire a cancelled event on the instance itself e.g

navigation.on('cancelled', (leaveNode, enterNode) => {
  // leaving `leaveNode` and entering `enterNode` was cancelled for reasons...
});

(We can also, at that point, call an onCancelled hook if one was supplied on the node to be focused.)

navigation.registerNode('myBox', {
  parent: 'myContainer',
  onCancelled: (leave, enter) => {
    // movement from `leave` to `enter` was cancelled, where `enter` is _this_ node itself
  }
}

The actual cancellation callback itself should also live against the node that was to be "entered", I'm thinking? Some kind of shouldCancel() callback.

navigation.registerNode('myBox', {
  parent: 'myContainer',
  onCancelled: (leave, enter) => {
    // movement from `leave` to `enter` was cancelled, where `enter` is _this_ node itself
  },
  shouldCancel: (leave, enter) : boolean => {
    // movement from `leave` to `enter` is happening, here is an opportunity
    // to call some business logic to `return false` and stop that movement
  }
}

Otherwise, perhaps a shouldCancel() on the instance itself? And it is called for every movement that happens. Before both in fact.

navigation
  .registerNode('root')
  .registerNode('box1')
  .registerNode('box2')
  .registerNode('box3')

navigation.shouldCancel((leave, enter => {
  // movement from `leave` to `enter` is happening, here is an opportunity
  // to call some business logic to `return true` and stop that movement
})

from lrud.

jordanholt avatar jordanholt commented on May 28, 2024

Interesting use case... I think I would prefer the first described implementation where the move operation provides a callback, and if that callback returns true, the move completes.

from lrud.

jordanholt avatar jordanholt commented on May 28, 2024

Another point worth thinking about is how this interacts (if at all) with the existing "overrides" mechanism.

from lrud.

do0g avatar do0g commented on May 28, 2024

This looks pretty good to me. Either of the node or instance solutions would probably work for us, but both would be very flexible.

from lrud.

thomascgray avatar thomascgray commented on May 28, 2024

Closing this issue, as it was fixed by #30

from lrud.

Related Issues (20)

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.