bbc / lrud

Left, Right, Up, Down. A spatial navigation library for devices with input via directional controls.
Apache License 2.0
98 stars 21 forks source link

Overrides of children are not cleaned up when unregistering parent node #86

Closed adrian-wozniak closed 3 years ago

adrian-wozniak commented 3 years ago

Describe the bug When node is unregistered then its overrides are cleaned as well, but if such node contains children that have overrides defined as well, than such overrides (those belonging to children) are not cleaned up.

To Reproduce

  test('unregistering a node should unregister the overrides of its children', () => {
    const navigation = new Lrud()

    navigation.registerNode('root')
    navigation.registerNode('a', { parent: 'root' })
    navigation.registerNode('ab', { parent: 'a' })
    navigation.registerNode('b', { parent: 'root' })

    navigation.registerOverride('override_a', {
      id: 'ab',
      direction: 'right',
      target: 'b'
    })

    navigation.unregister('a')

    expect(navigation.overrides).toEqual({})
  })

results with

 FAIL  src/unregister.test.js
  ● unregisterNode() › unregistering a node should unregister the overrides of its children

    expect(received).toEqual(expected) // deep equality

    - Expected  - 1
    + Received  + 7

    - Object {}
    + Object {
    +   "override_a": Object {
    +     "direction": "right",
    +     "id": "ab",
    +     "target": "b",
    +   },
    + }

       |     navigation.unregister('a')
       |
    >  |     expect(navigation.overrides).toEqual({})
       |                                  ^
       |   })
       |

Expected behavior Expected behavior is that all overrides related to unregistered node and its children should be cleaned up.

Screenshots No screenshots.

Additional context No additional context.

adrian-wozniak commented 3 years ago

@jordanholt Could I ask you to close this issue, as it is fixed?