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

Listen for new keys? #13

Open
frankier opened this issue Mar 5, 2015 · 4 comments
Open

Listen for new keys? #13

frankier opened this issue Mar 5, 2015 · 4 comments

Comments

@frankier
Copy link

frankier commented Mar 5, 2015

I'm interested in how to listen for new keys. It seems straightforward to listen for changes to an existing key if it's an observable, or listen for any change to the varhash or its children (I think - slightly hazy on how this works). But there doesn't seem to be any way to determine which/whether a key has been added or removed other than by diffing the whole hash with its previous value. Is this by design or would the addition of onaddition ondeletion methods which supply (key, value) and (key) to the callback respectively be reasonable?

@frankier
Copy link
Author

frankier commented Mar 6, 2015

Actually thinking about it, it is possible to hook into the creation function passed during construction. I guess diffing is more idiomatic?

@nrw
Copy link
Owner

nrw commented Mar 11, 2015

The design of observ-* focuses around being able to ask very efficiently "is this the same as last time I checked?" observs are the same if they are ===.

I think adding add and delete events is outside of the scope of this project, but I'd be interested to hear thoughts from @Raynos about the matter.

@Raynos
Copy link
Contributor

Raynos commented Mar 12, 2015

@nrw by design there should be an _diff field. ( https://github.com/nrw/observ-varhash/blob/master/index.js#L81 ).

When you listen to a change you can read the _diff field to get an efficient raw representation of what changed.

I've used this in the observ-array implementation to avoid implementing a naive diff of the full array each time anything changes.

@nrw
Copy link
Owner

nrw commented Mar 18, 2015

@frankier does inspecting the _diff field on a change currently allow for the "listen for new keys" extension you seek?

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

3 participants