[Feat] Add User change event listener and getters for OneSignal Id and external Id #1158
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
1 Line Summary
Adds
change
event listener,onesignalId
andexternalId
properties to OneSignal.User.Details
The User
change
event listener has the same name as the PushSubscriptionchange
event listener and should not be added to the same emitter because it will lead to both events being fired twice.Another emitter was added in the UserNamespace. All other namespaces still use the same static emitter from the OneSignal class.
The User emitter is static because there are two instances of UserNamespace where one is created on the property and again later when OneSignal initializes. When
addEventListener
is called by the dev, the event is being added before OneSignal initializes and to the property instance (new UserNamespace(false)
). To keep the event on the new instance after initialization, the emitter is static.Example:
Adding the user
change
event listener: https://github.com/OneSignal/OneSignal-Website-SDK/blob/main/express_webpack/index.html#L128Adding the push subscription
change
event listener: https://github.com/OneSignal/OneSignal-Website-SDK/blob/main/express_webpack/index.html#L122Future considerations:
externalId
to be a property onUser
Systems Affected
Validation
Tests
Manually tested
OneSignal.User.onesignalId
,OneSignal.User.externalId
, and Userchange
event firing when calling login and logout on the OneSignal WebSDK Sandbox.Info
Checklist
Programming Checklist
Interfaces:
Functions:
Typescript:
Other:
elem of array
syntax. PreferforEach
or usemap
context
if possible. Instead, we can pass it to function/constructor so that we don't callOneSignal.context
Screenshots
Info
Checklist
Related Tickets
This change is