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

Getter event #11

Open
krzysztofantczak opened this issue Jun 27, 2018 · 3 comments
Open

Getter event #11

krzysztofantczak opened this issue Jun 27, 2018 · 3 comments
Assignees

Comments

@krzysztofantczak
Copy link

krzysztofantczak commented Jun 27, 2018

Hey,

First of all, i love how i can get info about add/update on object properties, but.... Is it possible to somehow get notified when an object property is used? Like simple:

console.log(obj.some_prop);

ObservableSlim callback would be called with "read" type, or something like that? Even ugly and hacky way is good enough for my use case.

I had that working with native Proxy but Your lib makes it so much easier to handle all the other cases.

@ElliotNB ElliotNB self-assigned this Jun 27, 2018
@ElliotNB
Copy link
Owner

Currently Observable Slim doesn't support this, but it's a great enhancement idea. I'm going to look into this one and hopefully have the functionality added within a few days.

We have to be very careful with how we modify the get handler in the library. The get handler is invoked whenever a property is accessed -- iterating over large nested objects or merging objects will invoke the get handler many many times. It's important that the get handler remain as highly performant as possible in order to ensure the library doesn't bog down with large nested objects.

@krzysztofantczak
Copy link
Author

You are right. For my use case it's enough, when last prop gets the event. So for example, if i'll be reading path foo.bar.baz - baz will be the accessed property of object bar - no need to get another event on bar as property of foo. Well, unless i will read foo.bar :D Not sure if that's doable this way.

@ElliotNB
Copy link
Owner

Unfortunately it's not possible to only trigger the get handler for only a specific set of properties -- accessing any of the properties on an observed object would trigger the get handler.

In your example above, accessing the value foo.bar.baz would trigger the get handler twice -- once for foo.bar and another time for bar.baz. If you performed something like a object deep merge (e.g., the jQuery $.extend(true, {}, {}) the number of times the get handler is invoked can skyrocket if the objects are large and deeply nested. Keeping the code highly performant becomes very important -- particularly for browsers that requires the Proxy polyfill like IE11.

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

No branches or pull requests

2 participants