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

How to get new item from list ? #54

Open
riston opened this issue Apr 26, 2015 · 7 comments
Open

How to get new item from list ? #54

riston opened this issue Apr 26, 2015 · 7 comments

Comments

@riston
Copy link

riston commented Apr 26, 2015

I am using following model:

ItemList is a vector, which consists of model items. When listen to the "items" changes I get back the reference to object but the object itself is empty.

This case occurs when User A adds object the other User B session listens the event but it's empty or not yet synchronized. How to fix such issue ?

var items = host.get("/ItemList#items");

items.on("init", ....)
items.on(function (spec, val, source) {
   // This gets the correct type of object but, the properties are default values
  var item = items.getObject(val);
});
@abalandin
Copy link
Contributor

Try using onObjectStateReady(cb) instead of on("init", cb) to catch the moment when vector is synchronized.
Use onObjectEvent(cb) to handle all list items' events.

@riston
Copy link
Author

riston commented May 1, 2015

@abalandin thank you for the tip! One scenario more, when the server is down and for example on restart or crash the clients try to reconnect. Server is back online and then the "reon" event is thrown, should the items.onObjectEvent(cb) be also called ?

@sksizer
Copy link

sksizer commented May 1, 2015

A

  • Shane Sizer

On Fri, May 1, 2015 at 2:35 AM, Risto Novik notifications@github.com
wrote:

@abalandin thank you for the tip! One scenario more, when the server is down and for example on restart or crash the clients try to reconnect. Server is back online and then the "reon" event is thrown, should the items.onObjectEvent(cb) be also called ?

Reply to this email directly or view it on GitHub:
#54 (comment)

@gritzko
Copy link
Owner

gritzko commented May 1, 2015

Guys, if you have any suggestions regarding the API, it is the right time.

@gritzko
Copy link
Owner

gritzko commented May 1, 2015

@riston Events are emitted once operations arrive. Even if the server is dead, ops still may arrive. For example, from another tab in the same browser. (Not sure I fully understand the question.)

@riston
Copy link
Author

riston commented May 3, 2015

@gritzko, @abalandin could you explain more about the flow behind when and what event is thrown ?

For the collection there is a mixin called CollectionMethodsMixin with following methods:

  • onObjectEvent - Subscribe on collections entries events
  • offObjectEvent - Unsubscribe from collections entries' events
  • onObjectStateReady - Waits for collection to receive state from cache or uplink and then invokes passed callback

When the server crashes or client side user is in offline state. Later when the connection is restored or the server is restarted. What are the events which are thrown on the client, how to get list of objects that have changed ?

The Host module has listeners for state changes reon``,reoff,on,off```, what about the collection based objects ?

@gritzko
Copy link
Owner

gritzko commented May 14, 2015

Regarding server crash, that is no different from a regular case.
The RTT is a bit longer, of course, but op delivery is asynchronous in either case.
I mean, it may take 1 second or 1 hour to deliver an event, but the process is the same.
On reconnection, everything that arrived will be emitted.
0.4 has a planned feature of delivering such event bursts in batches, like

    model.on('set+', function (ev) {
        if (ev.constructor===Array) {
            // that is an event batch
        }
    });

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

4 participants