alkali
alkali copied to clipboard
Using `.property` on maps defined by keyBy should return original variable instance
Is it possible/desirable for maps generated by keyBy to return original variable instances?
class Foo extends Variable<{ Name: string, Id: number }> {}
const Collection = VArray.of(Foo)
const collection = new Collection([{
Name: 'Kerry',
Id: 123
}])
const index = collection.keyBy(model => model.get('Id'))
// fails
assert.strictEqual(index.property(123), collection.property(0))
// fails
assert(index.property(123) instanceof Foo)
let newProps = {
Name: 'Jerry',
Id: 123,
}
index.set(123, newProps)
// fails
assert.strictEqual(collection.get(0), newProps)
Just noticed that index.get(123) actually behaves this way. So that's cool that it's possible to retrieve the instance, but I'm wondering if this makes behavior inconsistent with valueOf()?
Also, would it be possible/desirable for the below to be equivalent?
// or index.property(123).put(newProps),
// depending on how you feel about above
index.get(123).put(newProps)
index.set(123, newProps)
I am not sure how that would be possible if property is really going to return a variable that represents a given id at any point in time, for example:
const collection = new Collection([])
const index = collection.keyBy(model => model.get('Id'))
const slot123 = index.property(123)
const kerry = new Foo({ Name: 'Kerry', Id: 123 })
collection.push(kerry)
slot123.valueOf() -> value of kerry
But, it is not possible for slot123 === kerry before the kerry instance even exists, as far as I can tell.