-
Notifications
You must be signed in to change notification settings - Fork 57
Initial attempt to decouple persistence #832
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
base: development
Are you sure you want to change the base?
Conversation
rmi22186
left a comment
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.
This looks good so far. Here are my comments for Monday morning. I didn't look at the tests since they may change given my feedback.
| persistence?.gs && | ||
| persistence?.gs.sid && |
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.
| persistence?.gs && | |
| persistence?.gs.sid && | |
| persistence?.gs?.sid && |
| mpInstance._Store.SDKConfig.sessionTimeout * 60000; | ||
|
|
||
| mpInstance._Store.globalTimer = window.setTimeout(function() { | ||
| // TODO: kill this global timer when ending session |
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.
good call
| persistence?.gs && | ||
| persistence?.gs.sid && |
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.
| persistence?.gs && | |
| persistence?.gs.sid && | |
| persistence?.gs?.sid && |
| persistence?.gs && | ||
| persistence?.gs.les && |
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.
| persistence?.gs && | |
| persistence?.gs.les && | |
| persistence?.gs?.les && |
| // debugger; | ||
|
|
||
| if (cookies.gs && !cookies.gs.sid) { | ||
| // QUESTION: What constitutes ending a session if we don't have persistence? |
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.
Addressed in earlier comments, but if we don' have persistence, then the expectation is that everything is saved to the store, so the logic would be if persistence is disabled, check the store instead
| messageType: Types.MessageType.SessionEnd, | ||
| }); | ||
|
|
||
| mpInstance._Store.sessionStartDate = null; |
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 line 182 was removed erroneously.
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 intentionally moved it to a new method Store.nullifySession() since it made sense to me to keep this grouped with the other nullify session logic. Is there a reason to not nullify the session start date when we nullify a session?
| mpInstance._Store.sessionId = persistence.gs.sid; | ||
| } | ||
|
|
||
| // TODO: Make this a store method |
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.
Can you clarify this TODO? Are you arguing that startNewSession should be on the store and not on the session module?
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 the answer the the above is yes. However I think there's a lot happening in this method that isn't just store related. Maybe there is a way to keep the session logic in session, and at the end, create a new method about updating the store's session attributes.
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 probably should have put this comment before the startNewSession method. My thought is that we're doing a lot of session related activities within the context of a store. Part of me thinks that we should split out the Session related persistence/store attributes into a seaprate Session object, so that the Session Manager can simply manage Sessions. As we've discussed, the store holds a lot of data about the state of the SDK, but a lot of unrelated modules directly modify the state which makes it hard to predict what the current state of the SDK is, so I thought a quick path to tidying things up would be to create a startNewSession method in the store to clean some things up.
src/store.ts
Outdated
| if (config.hasOwnProperty('usePersistence')) { | ||
| this.SDKConfig.usePersistence = config.usePersistence; | ||
| } else { | ||
| this.SDKConfig.usePersistence = false; |
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.
This should be true by default. Is this false because you are in the middle of development?
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.
Good catch. I made this default to false before we made our decision to default it to true. I'll update.
| // TODO: Maybe create an updateIdentity method? | ||
| // Store relevant identity settings into Store | ||
| mpInstance._Store.mpid = currentMPID; | ||
| mpInstance._Store.currentSessionMPIDs = currentSessionMPIDs; |
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.
Lines 20 and 21 can just be removed in favor of this approach.
Line 23 can be combined with the check on 18 so it's using Persistence or Store.
| mpInstance._Store.currentSessionMPIDs = currentSessionMPIDs; | |
| mpInstance._Store.currentSessionMPIDs = currentSessionMPIDs; | |
| persistence.cu = currentMPID; | |
| persistence.gs.csm = currentSessionMPIDs; |
| mpInstance._Store.setLastSeenTime(previousMPID); | ||
| } | ||
|
|
||
| // QUESTION: Does this only matter for cookies or do we need it for |
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.
It's called cookies, but actually applies to all persistence methods.
Also requires access to the DOM, so we may need a control for that to make sure dom exists.
| userAttributes?: Dictionary<UserAttributes>; | ||
| getUserAttributes?(mpid: MPID): UserAttributes; | ||
|
|
||
| // QUESTION: Is there a difference between this and currentUserIdentities? |
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.
| // QUESTION: Is there a difference between this and currentUserIdentities? | |
| // QUESTION: Is there a difference between this and currentUserIdentities? |
| this.setDeviceId = (deviceId: string): void => { | ||
| // TODO: This should update persistence | ||
| this.deviceId = deviceId; | ||
| mpInstance._Persistence.update(); |
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.
Do we still need to call update internally?
| }; | ||
|
|
||
| this.setConsentState = (mpid: MPID, consentState: ConsentState) => { | ||
| // QUESTION: What is the context here? |
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.
Comment can be removed as it is not necessary.
|
b6883b6 to
b8a1a8f
Compare
f03c5ed to
3df8d84
Compare
ca2b2d9 to
da03fea
Compare
905641c to
b16bdd2
Compare



Instructions
developmentSummary
Testing Plan
Reference Issue (For mParticle employees only. Ignore if you are an outside contributor)