Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using .property on maps defined by keyBy should return original variable instance #54

Open
kcrwfrd opened this issue Dec 12, 2017 · 2 comments

Comments

@kcrwfrd
Copy link

kcrwfrd commented Dec 12, 2017

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)
@kcrwfrd
Copy link
Author

kcrwfrd commented Dec 12, 2017

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)

@kriszyp
Copy link
Owner

kriszyp commented Dec 13, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants