@applicaster/zapp-react-native-bridge 14.0.0-alpha.1054425138 → 14.0.0-alpha.2847632144

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.
@@ -1,11 +1,8 @@
1
1
  import { createLogger } from "@applicaster/zapp-react-native-utils/logger";
2
2
  import { bridgeLogger } from "../logger";
3
3
  import { BehaviorSubject } from "rxjs";
4
- import { Storage } from "@applicaster/zapp-react-native-bridge/ZappStorage/Storage";
5
4
  import { localStorage } from "@applicaster/zapp-react-native-bridge/ZappStorage/LocalStorage";
6
- import { sessionStorage } from "@applicaster/zapp-react-native-bridge/ZappStorage/SessionStorage";
7
5
  import { getNamespaceAndKey } from "@applicaster/zapp-react-native-utils/appUtils/contextKeysManager/utils";
8
- import { StorageType } from "@applicaster/zapp-react-native-utils/appUtils/contextKeysManager/consts";
9
6
 
10
7
  export const { log_verbose, log_debug, log_warning, log_info, log_error } =
11
8
  createLogger({
@@ -37,28 +34,18 @@ export interface MultiSelectProvider {
37
34
  export class StorageMultiSelectProvider implements MultiSelectProvider {
38
35
  // TODO: Unsubscribe and remove when there is no listeners
39
36
  private static multiSelectProviders: Record<
40
- StorageType,
41
- Record<string, StorageMultiSelectProvider>
42
- > = {
43
- [StorageType.local]: {},
44
- [StorageType.session]: {},
45
- // TODO: not implemented yet
46
- [StorageType.secure]: {},
47
- };
48
-
49
- public static getProvider(
50
- keyNamespace: string,
51
- storage: StorageType = StorageType.local
52
- ): MultiSelectProvider {
53
- if (!this.multiSelectProviders[storage][keyNamespace]) {
54
- const storageImpl =
55
- storage === StorageType.session ? sessionStorage : localStorage;
56
-
57
- this.multiSelectProviders[storage][keyNamespace] =
58
- new StorageMultiSelectProvider(keyNamespace, storageImpl);
37
+ string,
38
+ StorageMultiSelectProvider
39
+ > = {};
40
+
41
+ public static getProvider(keyNamespace: string): StorageMultiSelectProvider {
42
+ if (!this.multiSelectProviders[keyNamespace]) {
43
+ this.multiSelectProviders[keyNamespace] = new StorageMultiSelectProvider(
44
+ keyNamespace
45
+ );
59
46
  }
60
47
 
61
- return this.multiSelectProviders[storage][keyNamespace];
48
+ return this.multiSelectProviders[keyNamespace];
62
49
  }
63
50
 
64
51
  private itemSubject: BehaviorSubject<string[] | null>;
@@ -66,10 +53,7 @@ export class StorageMultiSelectProvider implements MultiSelectProvider {
66
53
  private readonly key: string;
67
54
  private readonly namespace: string;
68
55
 
69
- private constructor(
70
- keyNamespace: string,
71
- private storage: Storage
72
- ) {
56
+ private constructor(keyNamespace: string) {
73
57
  const { namespace, key } = getNamespaceAndKey(keyNamespace);
74
58
 
75
59
  if (!key) {
@@ -78,7 +62,7 @@ export class StorageMultiSelectProvider implements MultiSelectProvider {
78
62
 
79
63
  this.key = key;
80
64
  this.namespace = namespace;
81
- this.storage.addListener?.({ key, namespace }, this.reloadItems);
65
+ localStorage.addListener?.({ key, namespace }, this.reloadItems);
82
66
 
83
67
  this.itemSubject = new BehaviorSubject([]);
84
68
 
@@ -100,7 +84,7 @@ export class StorageMultiSelectProvider implements MultiSelectProvider {
100
84
  public getObservable = (): BehaviorSubject<string[]> => this.itemSubject;
101
85
 
102
86
  private async getSetOfCurrentItems() {
103
- const currentResult: string = await this.storage.getItem(
87
+ const currentResult: string = await localStorage.getItem(
104
88
  this.key,
105
89
  this.namespace
106
90
  );
@@ -111,7 +95,7 @@ export class StorageMultiSelectProvider implements MultiSelectProvider {
111
95
  private async updateItemsAndNotifyObservers(currentItems: Set<string>) {
112
96
  const arrayOfItems = Array.from(currentItems);
113
97
  const newValue = arrayOfItems.join(",");
114
- await this.storage.setItem(this.key, newValue, this.namespace);
98
+ await localStorage.setItem(this.key, newValue, this.namespace);
115
99
 
116
100
  this.itemSubject.next(arrayOfItems);
117
101
  }
@@ -166,14 +150,14 @@ export class StorageMultiSelectProvider implements MultiSelectProvider {
166
150
  };
167
151
 
168
152
  public removeAllItems = async (): Promise<void> => {
169
- await this.storage.removeItem(this.key, this.namespace);
153
+ await localStorage.removeItem(this.key, this.namespace);
170
154
  log_debug(`removeAllItems: Removing all items, current items: ${[]}`);
171
155
 
172
156
  this.itemSubject.next([]);
173
157
  };
174
158
 
175
159
  public getSelectedAsync = async (): Promise<string[]> => {
176
- const value = await this.storage.getItem(this.key, this.namespace);
160
+ const value = await localStorage.getItem(this.key, this.namespace);
177
161
  const selectedItems = value ? value.split(",") : [];
178
162
  this.itemSubject.next(selectedItems);
179
163
 
@@ -31,7 +31,7 @@ export class StorageSingleValueProvider implements SingleValueProvider {
31
31
  StorageSingleValueProvider
32
32
  > = {};
33
33
 
34
- public static getProvider(keyNamespace: string): SingleValueProvider {
34
+ public static getProvider(keyNamespace: string): StorageSingleValueProvider {
35
35
  if (!this.singleValueProviders[keyNamespace]) {
36
36
  this.singleValueProviders[keyNamespace] = new StorageSingleValueProvider(
37
37
  keyNamespace
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applicaster/zapp-react-native-bridge",
3
- "version": "14.0.0-alpha.1054425138",
3
+ "version": "14.0.0-alpha.2847632144",
4
4
  "description": "Applicaster Zapp React Native modules",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -32,7 +32,7 @@
32
32
  "homepage": "https://github.com/applicaster/quickbrick#readme",
33
33
  "dependencies": {
34
34
  "@applicaster/zapp-pipes-dev-kit": "1.4.7",
35
- "@applicaster/zapp-react-native-utils": "14.0.0-alpha.1054425138",
35
+ "@applicaster/zapp-react-native-utils": "14.0.0-alpha.2847632144",
36
36
  "md5": "^2.3.0",
37
37
  "uuid": "^3.3.2"
38
38
  },
@@ -1,92 +0,0 @@
1
- import { BehaviorSubject } from "rxjs";
2
- import { log_debug, SingleValueProvider } from "./StorageSingleSelectProvider";
3
-
4
- export const screenStates: Record<string, Record<string, string>> = {};
5
-
6
- export class ScreenSingleValueProvider implements SingleValueProvider {
7
- private static providers: Record<
8
- string,
9
- Record<string, SingleValueProvider>
10
- > = {};
11
-
12
- // TODO: Screen State should be stored outside of this class and should be shared with screen multi-select provider
13
- public static getState(screenRoute: string): Record<string, string> {
14
- return screenStates[screenRoute] || {};
15
- }
16
-
17
- public static getProvider(
18
- key: string,
19
- screenRoute: string
20
- ): SingleValueProvider {
21
- if (!key) {
22
- throw new Error("ScreenSingleValueProvider: Key is required");
23
- }
24
-
25
- if (!screenRoute) {
26
- throw new Error("ScreenSingleValueProvider: Screen route is required");
27
- }
28
-
29
- if (!this.providers[screenRoute]) {
30
- this.providers[screenRoute] = {};
31
- }
32
-
33
- if (!this.providers[screenRoute][key]) {
34
- this.providers[screenRoute][key] = new ScreenSingleValueProvider(
35
- key,
36
- screenRoute
37
- );
38
- }
39
-
40
- if (!screenStates[screenRoute]) {
41
- screenStates[screenRoute] = {};
42
- }
43
-
44
- return this.providers[screenRoute][key];
45
- }
46
-
47
- // @ts-ignore
48
- private valueSubject: BehaviorSubject<string | null>;
49
- p;
50
- // @ts-ignore
51
- private constructor(
52
- private key: string,
53
- private route: string
54
- ) {
55
- if (!key) {
56
- throw new Error("ScreenSingleValueProvider: Key is required");
57
- }
58
-
59
- // localStorage.addListener?.({ key, namespace }, this.reloadValue);
60
-
61
- this.valueSubject = new BehaviorSubject<string | null>(null);
62
-
63
- void this.getValueAsync();
64
- log_debug("ScreenSingleValueProvider: Initializing");
65
- }
66
-
67
- clearValue(): Promise<void> {
68
- delete [this.route][this.key];
69
- this.valueSubject.next(null);
70
-
71
- return Promise.resolve();
72
- }
73
-
74
- getObservable(): BehaviorSubject<string | null> {
75
- return this.valueSubject;
76
- }
77
-
78
- getValue(): string | null {
79
- return this.valueSubject.value;
80
- }
81
-
82
- getValueAsync(): Promise<string | null> {
83
- return Promise.resolve(this.valueSubject.value);
84
- }
85
-
86
- setValue(value: string): Promise<void> {
87
- screenStates[this.route][this.key] = value;
88
- this.valueSubject.next(value);
89
-
90
- return Promise.resolve();
91
- }
92
- }
@@ -1,119 +0,0 @@
1
- import { log_debug, MultiSelectProvider } from "./StorageMultiSelectProvider";
2
- import { BehaviorSubject } from "rxjs";
3
- import { screenStates } from "./ScreenSingleValueProvider";
4
-
5
- export class ScreenMultiSelectProvider implements MultiSelectProvider {
6
- // @ts-ignore
7
- private itemSubject: BehaviorSubject<string[] | null>;
8
-
9
- private static providers: Record<
10
- string,
11
- Record<string, MultiSelectProvider>
12
- > = {};
13
-
14
- public static getProvider(
15
- key: string,
16
- screenRoute: string
17
- ): MultiSelectProvider {
18
- if (!key) {
19
- throw new Error("ScreenSingleValueProvider: Key is required");
20
- }
21
-
22
- if (!screenRoute) {
23
- throw new Error("ScreenSingleValueProvider: Screen route is required");
24
- }
25
-
26
- if (!this.providers[screenRoute]) {
27
- this.providers[screenRoute] = {};
28
- }
29
-
30
- if (!this.providers[screenRoute][key]) {
31
- this.providers[screenRoute][key] = new ScreenMultiSelectProvider(
32
- key,
33
- screenRoute
34
- );
35
- }
36
-
37
- if (!screenStates[screenRoute]) {
38
- screenStates[screenRoute] = {};
39
- }
40
-
41
- return this.providers[screenRoute][key];
42
- }
43
-
44
- // @ts-ignore
45
- private constructor(
46
- private key: string,
47
- private route: string
48
- ) {
49
- if (!key) {
50
- throw new Error("StorageMultiSelectProvider: Key is required");
51
- }
52
-
53
- this.key = key;
54
- // this.storage.addListener?.({ key, namespace }, this.reloadItems);
55
-
56
- this.itemSubject = new BehaviorSubject([]);
57
-
58
- void this.getSelectedAsync();
59
- log_debug("StorageMultiSelectProvider: Initializing");
60
- }
61
-
62
- private getSetOfCurrentItems() {
63
- const currentResult: string = screenStates[this.route][this.key];
64
-
65
- return new Set(currentResult ? currentResult.split(",") : []);
66
- }
67
-
68
- addItem(item: string): Promise<void> {
69
- const items = this.getSetOfCurrentItems();
70
- items.add(item);
71
- screenStates[this.route][this.key] = Array.from(items).join(",");
72
- this.itemSubject.next(Array.from(items) || []);
73
-
74
- log_debug(
75
- `addItem: item added: ${item}, current items: ${Array.from(items)}`
76
- );
77
-
78
- return Promise.resolve();
79
- }
80
-
81
- addItems(_items: string[]): Promise<void> {
82
- return Promise.resolve();
83
- }
84
-
85
- public getObservable = (): BehaviorSubject<string[]> => this.itemSubject;
86
-
87
- getSelectedAsync(): Promise<string[]> {
88
- const values = screenStates[this.route][this.key]?.split(",");
89
- this.itemSubject.next(values || []);
90
-
91
- return Promise.resolve(values || []);
92
- }
93
-
94
- getSelectedItems(): string[] {
95
- return this.itemSubject.value;
96
- }
97
-
98
- removeAllItems(): Promise<void> {
99
- return Promise.resolve();
100
- }
101
-
102
- removeItem(item: string): Promise<void> {
103
- const items = this.getSetOfCurrentItems();
104
- items.delete(item);
105
-
106
- screenStates[this.route][this.key] = Array.from(items).join(",");
107
- this.itemSubject.next(Array.from(items) || []);
108
-
109
- return Promise.resolve();
110
- }
111
-
112
- removeItems(_items: string[]): Promise<void> {
113
- return Promise.resolve();
114
- }
115
-
116
- setSelectedItems(_items: string[]): Promise<void> {
117
- return Promise.resolve();
118
- }
119
- }