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
Add actsAsOrderedSet #84
Conversation
We may want to change the flag from |
@dgeb yeah, that does seem more accurate. I'm hoping to get this tied up this weekend (need to do ember-orbit and check everything against an app). Could you give me an overview of how actsAsSet actually works with ember-orbit? I can see that orbit.js only allows updateLink to be used by actsAsSet hasManys but I can't see how ember-orbit would switch between using addLink and updateLink (I'd expect https://github.com/orbitjs/ember-orbit/blob/master/lib/ember-orbit/links/has-many-array.js to use updateLink for actsAsSet). |
Is there any reason to not use an array for all |
@gnarf it's a good question, we'd need to add some more explicit handling of dupes (using a hash avoids having to worry about this but I'll have to add it anyway for actsAsOrderedSet). You'll see in this PR I've added the index as an additional optional arg to addLink and removeLink. All in all though, always using an orderedSet does seem simpler. |
The point about dupes is an important one... |
Been looking at firebase and they make a great point about arrays being difficult to update in a distributed environment, it's a case of last write wins when really you want to merge the changes together. I'm now considering switching to using a priority field on each of the items in the list. This has it's own problems, i.e. you can end up with multiple items in the list with the same priority but at least you don't lose items in the list. It is resolvable however because you can stretch the list out and give the overlapping items unique priorities at a later time. |
That's why I think this is only acceptable if the entire array is updated as a set, and why I wanted this flag to be |
@opsb are you still pursuing |
@dgeb I'm circling back round to it after I've done the integration with Firebase. Because I'm integrating two unfamiliar techs (orbit.js and firebase) I wanted to see the big picture before I finished off with this branch. I'm still undecided about the best way to manage arrays for my app but I will finish off this PR either way. |
@opsb makes sense - thanks 👍 |
7f83973
to
b1a39fb
Compare
@dgeb this PR is ready to go now. Let me know if there's anything you want me to amend. |
The corresponding PR for ember-orbit is at orbitjs/ember-orbit#56 |
b1a39fb
to
680e9ed
Compare
680e9ed
to
d82de85
Compare
Rebased against master |
It's kinda sad that we never got this in.... It needs a rebase again 😦 I thought we had and was all telling @mzgoddard about it as if it were a real thing 😄 |
I'm a little reticent now. I came across issues with old operations overwriting newer ones when using memory-source with a remote source. Currently there isn't any mechanism in orbit to establish which operation is newer so there's no way to know which one to prefer. This is a fairly thorny topic so I think we'll have to park it for now. |
Should we close this PR @opsb , will you update it / rebase it / work on it? |
I've been giving this some thought lately actually. The original problem was that there was no way to tell if an operation had been applied to an array or not. The operation relies on the index positioning so if an array is modified after the original operation has been applied then if the operation arrives at the source again (which is relatively common) then you can easily get stuck in infinite loops with two operations churning on the arrays. Now there's a transaction log however it's possible to check if a transaction has been applied already and stop the bad sequence. That said, there's obviously been a fair few changes since this PR was put together and it's probably better to put it together again from scratch using this one as inspiration. |
Alrighty - going to close this then! |
@dgeb this is still a work in progress, I've made the updates to orbit.js and the tests look good. I had a quick go at integrating it with ember-orbit in an app I'm working on but it looks like I'll need to spend some time looking at how ember-orbit and orbit.js integrate tomorrow. I've put this up in case you get a chance to review.