Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Feature/observable throttle#363

Merged
Urigo merged 11 commits into
masterfrom
feature/observable-throttle
Aug 11, 2016
Merged

Feature/observable throttle#363
Urigo merged 11 commits into
masterfrom
feature/observable-throttle

Conversation

@dotansimha
Copy link
Copy Markdown
Collaborator

@hongbo-miao @Urigo
What do you think?

Looks now that the fetch called only twice when you have a lot of objects, and once when you unsubscribe from the Meteor publication.
I chose 16ms because it's the minimum timeframe between WebSocket messages, and under that is too fast (it's equivalent to 60fps).

@hongbo-miao Do you have any use case you can try besides the example I provided?

Thanks

@hongbo-miao
Copy link
Copy Markdown
Contributor

hongbo-miao commented Aug 1, 2016

Yeah, I can try in my app! (just feel that comfortable delaying 16ms, hope we can find a better way later)

@dotansimha
Copy link
Copy Markdown
Collaborator Author

dotansimha commented Aug 1, 2016

We could easily solve it if Meteor expose callback for Cursor change by DDP message (can easily implemented by using hash for each DDP message, and update the hash of the Cursor only if the DDP message relevant to the message).
So when you got DDP message with a lot of object, the hash updates only once, and the callback of the Cursor update will be called once.
@Urigo what do you think?

@hongbo-miao
Copy link
Copy Markdown
Contributor

hongbo-miao commented Aug 1, 2016

@dotansimha I am using #3eaca130942872f95c761d413af8074a991e08c1

3 products in database.

For me, PRODUCTS_COLLECTION_UPDATED is called 3 times now (but better than before, which is 6 times).

After unsubscribing, note the first one's PRODUCTS_COLLECTION_UPDATED payload still has 3 items.

image

@hongbo-miao
Copy link
Copy Markdown
Contributor

hongbo-miao commented Aug 2, 2016

Ha, that is one of main reasons that I love ngrx (Redux). It helps you know how Meteor reactivity works, and when it runs. And nice for performance, making it exactly runs once, not twice.

observer.next(cursor.fetch());
};
var rawHandleChange = function () { return Zone.current.run(function () { return observer.next(cursor.fetch()); }); };
var handleChange = _.throttle(rawHandleChange, COLLECTION_EVENTS_DEBOUNCE_TIMEFRAME, { trailing: true });
Copy link
Copy Markdown
Collaborator

@barbatus barbatus Aug 9, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dotansimha What do you think if we put _.debounce here instead _.throttle? I feel like it might be a better fit here since _.throttle always runs the callback every 16ms and _.debounce groups calls together based on the 16ms gap.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. I will try it.

@dotansimha
Copy link
Copy Markdown
Collaborator Author

@hongbo-miao @barbatus @Urigo
Applied some of @barbatus ideas to run within the Zone of the component who actually dispatched the store action.
Looks fine.
Also, replace throttle with debounce, and increased the limit of the debounce to 100ms.
Now seems like the subscribe and unsubscribe called only once.

@hongbo-miao what do you think ?

@dotansimha dotansimha self-assigned this Aug 10, 2016
@dotansimha dotansimha added this to the 0.6.3 milestone Aug 10, 2016
@Urigo Urigo merged commit 074546b into master Aug 11, 2016
@hongbo-miao
Copy link
Copy Markdown
Contributor

hongbo-miao commented Aug 11, 2016

Thanks for the awesome work!
@dotansimha Just need change a little bit of unsubscribe part of codes in the demo, and then it is perfect!
Please check this https://github.com/dotansimha/angular2-meteor-with-observables/pull/6

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants