libs icon indicating copy to clipboard operation
libs copied to clipboard

feat(reactive): support deletion of overriden properties in child context

Open lowlighter opened this issue 1 year ago • 1 comments

When using Scope.with, if an overriden property is deleted from child context, it should not reappear from parent context.

This is currently not supported because it adds a priori a lot of complexity (we need to track which property from the root object were overriden and then deleted, in addition to remove this flag if it's set again, and everything without impacting parent context).

The following test case can be used to test this behaviour:

test("all")("Scope.with() contexts operates unidirectionaly when value is overidden from parent (delete operation)", () => {
  const a = new Context({ d: 0 })
  const b = a.with<testing>({ d: 1 })
  const listeners = { a: fn(), b: fn() }
  a.addEventListener("change", listeners.a)
  b.addEventListener("change", listeners.b)
  delete b.target.d
  expect(a.target.d).toBe(0)
  expect(b.target.d).toBeUndefined()
  expect(a.target).toHaveProperty("d")
  expect(b.target).not.toHaveProperty("d")
  expect(listeners.a).toHaveBeenCalledTimes(0)
  expect(listeners.b).toHaveBeenCalledTimes(1)
})

lowlighter avatar May 31 '24 22:05 lowlighter