@amedia/user 0.14.89 → 0.14.90

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -124,19 +124,24 @@ Full usage example:
124
124
  ```ts
125
125
  import { UserDataRequest } from '...';
126
126
 
127
- new UserDataRequest()
127
+ const unsubscribe = new UserDataRequest()
128
128
  .withAttributes(['name', 'trackingKey'])
129
129
  .withStorage(['my_namespace']) // You might know this as Europa
130
130
  .subscribe(({ attributes, state, storage }) => {
131
131
  console.log(attributes, state, storage);
132
132
  });
133
+
134
+ // If you wish to unsubscribe from further updates:
135
+ unsubscribe();
133
136
  ```
134
137
 
135
- The callback you supplied to subscribe is called whenever there are any changes to the properties you have requested, so be prepared to rerender.
138
+ The callback you supplied to subscribe is called whenever there are any changes to the properties you have requested, so be prepared to re-render.
136
139
 
137
140
  Also, your requested properties might not arrive all at once. This callback will be called whenever we get data in from the various services.
138
141
 
139
- #### Fetching all the data once (no rerenders)
142
+ Should you wish to end your subscription, just call the returned function from subscribe.
143
+
144
+ #### Fetching all the data once (no re-renders)
140
145
 
141
146
  In many use cases it's more convenient to just wait until everything is ready, so you don't have to handle multiple callbacks. In these cases it's easier to call `.fetch()`. This method will return a `Promise` that resolves the same object you would get in the `subscribe` callback.
142
147
 
@@ -154,9 +159,9 @@ new UserDataRequest()
154
159
  });
155
160
  ```
156
161
 
157
- Fetch will wait until it has all the data you requested before resolving, unless the user is not currently logged in. Internally `.fetch()` will use `.subscribe()` and just wait until everything is ready before resolving the returned promise.
162
+ Fetch will wait until it has all the data you requested before resolving, unless the user is not currently logged in. Internally `.fetch()` will use `.subscribe()` and just wait until everything is ready before unsubscribing and then resolving the returned promise.
158
163
 
159
- If you really need to render the user's name or get its uuid etc. as fast as possible, use `.subscribe()`, if not, this is probably easier.
164
+ If you really need to render the user's name or get their uuid etc. as fast as possible, use `.subscribe()`, if not, this is probably easier.
160
165
 
161
166
  ##### Timeouts
162
167
 
package/dist/user.d.ts CHANGED
@@ -23,6 +23,7 @@ type PrivacyPreferences = {
23
23
  };
24
24
 
25
25
  type Millis = number;
26
+ type UnsubscribeFn = () => void;
26
27
  declare class UserDataRequest<UA extends UserAttributes, S extends {
27
28
  [index: string]: unknown;
28
29
  }, Attributes extends Array<keyof UA>, Namespaces extends Array<string>, SubscribeResponse extends Record<string, unknown> & {
@@ -35,6 +36,7 @@ declare class UserDataRequest<UA extends UserAttributes, S extends {
35
36
  static FETCH_TIMEOUT: Millis;
36
37
  private fetchTimeoutId;
37
38
  private lastReceivedData?;
39
+ private subscriptionEventListeners;
38
40
  constructor(attributes?: Attributes, namespaces?: Namespaces);
39
41
  withAttributes<NewAttributes extends Array<keyof UA>>(attributes: NewAttributes): UserDataRequest<UA, S, (Attributes[number] & NewAttributes[number])[], Namespaces, SubscribeResponse & {
40
42
  attributes: Pick<UA, Attributes[number] & NewAttributes[number]>;
@@ -42,10 +44,11 @@ declare class UserDataRequest<UA extends UserAttributes, S extends {
42
44
  withStorage<NewNamespaces extends Array<string>>(namespaces: NewNamespaces): UserDataRequest<UA, S, Attributes, (Namespaces[number] & NewNamespaces[number])[], SubscribeResponse & {
43
45
  storage: Pick<S, Namespaces[number] & NewNamespaces[number]>;
44
46
  }>;
45
- subscribe(onData: (data: SubscribeResponse) => void): void;
47
+ subscribe(onData: (data: SubscribeResponse) => void): UnsubscribeFn;
46
48
  fetch(options?: {
47
49
  timeout?: Millis;
48
50
  }): Promise<SubscribeResponse>;
51
+ private unsubscribe;
49
52
  private clearFetchTimeout;
50
53
  private startFetchTimeout;
51
54
  private processUserAttributesEvent;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amedia/user",
3
- "version": "0.14.89",
3
+ "version": "0.14.90",
4
4
  "description": "Client lib for working with aID user and associated data",
5
5
  "repository": "https://github.com/amedia/amedia-user-js",
6
6
  "author": "Amedia Utvikling (ID og data)",