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

Making stores async #717

Merged
merged 3 commits into from
Dec 15, 2015
Merged

Making stores async #717

merged 3 commits into from
Dec 15, 2015

Conversation

rmachielse
Copy link
Contributor

Replaces #714

This pull request makes stores async by default.
That will allow people to build stores that persist on asynchronous storage (like chrome app storage).

@rmachielse
Copy link
Contributor Author

Hi @marcoow, I rebased and added backwards compatibility with older stores, so I think this branch is ready.

@marcoow marcoow added this to the 1.x milestone Oct 21, 2015
@marcoow
Copy link
Member

marcoow commented Oct 21, 2015

Yeah, saw that - thanks! This will most likely go into 1.1.

@LongLiveCHIEF
Copy link

👍

@marcoow
Copy link
Member

marcoow commented Nov 19, 2015

@rmachielse: can you rebase this on the latest master?

@rmachielse
Copy link
Contributor Author

@marcoow Done!

return session.authenticate('authenticator').then(() => {
let properties = store.restore();
delete properties.authenticator;
it('persists its content in the store', (done) => {
Copy link
Member

Choose a reason for hiding this comment

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

You can simply return a promise from the test instead of using done - I think that's a bit cleaner and also consistent with the rest of the code base then.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I replaced done with return blocks where possible

let result = this.store[method].apply(this.store, params);
if (typeof result === 'undefined' || typeof result.then === 'undefined') {
Ember.deprecate(`Ember Simple Auth: Synchronous stores have been deprecated. Make sure your custom store's ${method} method returns a promise.`, false);
return Ember.RSVP.Promise.resolve(result || {});
Copy link
Member

Choose a reason for hiding this comment

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

Not sure the || {} is actually correct - persist doesn't return anything so this should also not resolve with a value in that case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, || {} it is not really necessary, but it might prevent older custom stores that return nothing in some cases from breaking

Copy link
Member

Choose a reason for hiding this comment

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

If a custom store returns nothing from restore than the error is in the store - this shouldn't be fixed in the internal session. Also now e.g. persist would resolve with {} which doesn't really make sense especially when it actually persisted sth. different than {}.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright, I'll just remove that part here

@rmachielse
Copy link
Contributor Author

@marcoow I updated for most of your comments. I'll add some more tests as well

@marcoow
Copy link
Member

marcoow commented Nov 20, 2015

@rmachielse: great!

@rmachielse
Copy link
Contributor Author

@marcoow I've been working on making the session-stores clear in two steps, to make it recoverable in case the invalidation fails. However, this adds much more complexity. No solution will ever be 100% correct, because if session-store#clear is being rejected, we don't know what that means about wether the data is still there or not. I think it would be better to keep the previous behavior, but to throw an exception when unexpected behavior occurs.

You can see my changes on this in the last commit I pushed. What do you think?

@marcoow
Copy link
Member

marcoow commented Nov 30, 2015

Yeah, I think you're right. I think what we should do is to return RSVP.all(cleanStore, invalidateWithAuthenticator) and then the application code would have to figure out what to do when the promise rejects (probably ignore it as there's no way to handle it really).

@rmachielse rmachielse force-pushed the async-stores branch 2 times, most recently from ddd1ca0 to 7b7a45d Compare December 4, 2015 19:08
@rmachielse
Copy link
Contributor Author

@marcoow I've updated for your recent concerns again. The tests fail because of a failure on the latest beta. I think this will happen for master too. Want me to look into it?

@marcoow
Copy link
Member

marcoow commented Dec 7, 2015

@rmachielse: thanks - I'm looking into fixing the build for master. You can rebase this branch then once that's fixed.

this.restore().then((restoredContent) => {
this._lastData = restoredContent;
resolve();
}, resolve);
Copy link
Member

Choose a reason for hiding this comment

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

Resolving just hides the error in this case. I think the best option here is to just not use restore to set _lastData but simply set it directly so that there would be only one async operation going on here. This of course potentially requires other methods to be updated as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can agree on that, I have updated

@marcoow
Copy link
Member

marcoow commented Dec 7, 2015

Left 2 comments again. Sorry for this taking forever to merge bug it's actually quite a big change and we need to make sure we get it right. Looking forward to merging this soon!

@rmachielse rmachielse force-pushed the async-stores branch 3 times, most recently from 5eec16e to 53451a5 Compare December 12, 2015 15:39
@rmachielse
Copy link
Contributor Author

@marcoow I have updated again. No problem, I'm glad you take this project serious. If we can get this released this year I'm happy!

isAuthenticated: false,
authenticator: null
});
Ember.set(this.content, 'authenticated', {});
Copy link
Member

Choose a reason for hiding this comment

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

I think there must be a this.endPropertyChanges(); after this line as well as otherwise it would remain in the state set by beginPropertyChanges above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, missed those, I updated both cases

@marcoow
Copy link
Member

marcoow commented Dec 14, 2015

@rmachielse: just had 2 last comments ;)

I'm currently running the dummy app though and recognized that session syncing doesn't seem to work anymore - don't know why yet, I'm debugging it.

@marcoow
Copy link
Member

marcoow commented Dec 14, 2015

It looks like a promise ends up being stored in the session:
bildschirmfoto 2015-12-14 um 18 44 38

@marcoow
Copy link
Member

marcoow commented Dec 14, 2015

That seems to be a problem with session restoration. It happens as soon as I open a second tab and also seems to be somehow recursive. It seems to keep adding serialized promises into the session until the browser crashes.

@marcoow
Copy link
Member

marcoow commented Dec 14, 2015

{"_id":7492,"_state":1,"_result":{"_id":7488,"_state":1,"_result":{"_id":7484,"_state":1,"_result":{"_id":7484,"_state":1,"_result":{"_id":7480,"_state":1,"_result":{"_id":7476,"_state":1,"_result":{"_id":7472,"_state":1,"_result":{"_id":7468,"_state":1,"_result":{"_id":7464,"_state":1,"_result":{"_id":7460,"_state":1,"_result":{"_id":7456,"_state":1,"_result":{"_id":7452,"_state":1,"_result":{"_id":7448,"_state":1,"_result":{"_id":7444,"_state":1,"_result":{"_id":7440,"_state":1,"_result":{"_id":7436,"_state":1,"_result":{"_id":7432,"_state":1,"_result":{"_id":7428,"_state":1,"_result":{"_id":7424,"_state":1,"_result":{"_id":7420,"_state":1,"_result":{"_id":7416,"_state":1,"_result":{"_id":7412,"_state":1,"_result":{"_id":7408,"_state":1,"_result":{"_id":7404,"_state":1,"_result":{"_id":7400,"_state":1,"_result":{"_id":7396,"_state":1,"_result":{"_id":7392,"_state":1,"_result":{"_id":7388,"_state":1,"_result":{"_id":7384,"_state":1,"_result":{"_id":7380,"_state":1,"_result":{"_id":7376,"_state":1,"_result":{"_id":7372,"_state":1,"_result":{"_id":7368,"_state":1,"_result":{"_id":7364,"_state":1,"_result":{"_id":7360,"_state":1,"_result":{"_id":7356,"_state":1,"_result":{"_id":7352,"_state":1,"_result":{"_id":7348,"_state":1,"_result":{"_id":7344,"_state":1,"_result":…

funny bug (it's actually a lot more - this is just a short excerpt)…

@rmachielse
Copy link
Contributor Author

@marcoow I am able to reproduce this, looking into it now!

@rmachielse
Copy link
Contributor Author

@marcoow I found the bug, it turned out I forgot to update _bindToStorageEvents in the addon/session-stores/local-storage.js. Sorry, it should be fixed now!

marcoow added a commit that referenced this pull request Dec 15, 2015
@marcoow marcoow merged commit d8fe402 into mainmatter:master Dec 15, 2015
@marcoow
Copy link
Member

marcoow commented Dec 15, 2015

@rmachielse: thanks a lot for the effort, I'm really happy with the outcome!

@rmachielse
Copy link
Contributor Author

Thank you a lot! Let me know when there's anything else I can do!

@sly7-7
Copy link
Contributor

sly7-7 commented Dec 13, 2016

I guess this is not a big deal, but this results in the inspector promises tab going crazy. (the sync_data function beeing called recursively) (btw, instead of calling cancel + later, calling throttle or debounce do the same job, right ?)

@marcoow
Copy link
Member

marcoow commented Dec 13, 2016

@sly7-7: good point - want to submit a PR that replaces cancel/later with debounce?

@sly7-7
Copy link
Contributor

sly7-7 commented Dec 13, 2016

here you go #1131 😄

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