-
Notifications
You must be signed in to change notification settings - Fork 602
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
Making stores async #717
Conversation
9cec3ff
to
e3fbf6d
Compare
Hi @marcoow, I rebased and added backwards compatibility with older stores, so I think this branch is ready. |
Yeah, saw that - thanks! This will most likely go into 1.1. |
👍 |
@rmachielse: can you rebase this on the latest master? |
e3fbf6d
to
a11b7ef
Compare
@marcoow Done! |
return session.authenticate('authenticator').then(() => { | ||
let properties = store.restore(); | ||
delete properties.authenticator; | ||
it('persists its content in the store', (done) => { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
2548472
to
1911837
Compare
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 || {}); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 {}
.
There was a problem hiding this comment.
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
1911837
to
c121165
Compare
@marcoow I updated for most of your comments. I'll add some more tests as well |
@rmachielse: great! |
c121165
to
8ac0bc8
Compare
8ac0bc8
to
b15c19b
Compare
@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 You can see my changes on this in the last commit I pushed. What do you think? |
Yeah, I think you're right. I think what we should do is to return |
ddd1ca0
to
7b7a45d
Compare
@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? |
@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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
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! |
5eec16e
to
53451a5
Compare
@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', {}); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
@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. |
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. |
{"_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)… |
@marcoow I am able to reproduce this, looking into it now! |
…ving async store tests
53451a5
to
6e55271
Compare
@marcoow I found the bug, it turned out I forgot to update |
@rmachielse: thanks a lot for the effort, I'm really happy with the outcome! |
Thank you a lot! Let me know when there's anything else I can do! |
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 ?) |
@sly7-7: good point - want to submit a PR that replaces |
here you go #1131 😄 |
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).