@applicaster/zapp-react-native-bridge 13.0.8 → 13.0.9-alpha.8843371874
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@applicaster/zapp-react-native-bridge",
|
|
3
|
-
"version": "13.0.
|
|
3
|
+
"version": "13.0.9-alpha.8843371874",
|
|
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": "13.0.
|
|
35
|
+
"@applicaster/zapp-react-native-utils": "13.0.9-alpha.8843371874",
|
|
36
36
|
"md5": "^2.3.0",
|
|
37
37
|
"uuid": "^3.3.2"
|
|
38
38
|
},
|
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
import { createLogger } from "@applicaster/zapp-react-native-utils/logger";
|
|
2
|
-
import { bridgeLogger } from "../logger";
|
|
3
|
-
import { BehaviorSubject } from "rxjs";
|
|
4
|
-
import { localStorage } from "@applicaster/zapp-react-native-bridge/ZappStorage/LocalStorage";
|
|
5
|
-
import { getNamespaceAndKey } from "@applicaster/zapp-react-native-utils/appUtils/contextKeysManager/utils";
|
|
6
|
-
|
|
7
|
-
export const { log_verbose, log_debug, log_warning, log_info, log_error } =
|
|
8
|
-
createLogger({
|
|
9
|
-
category: "StorageMultiSelectProvider",
|
|
10
|
-
subsystem: "zapp-react-native-bridge",
|
|
11
|
-
parent: bridgeLogger,
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
export interface MultiSelectProvider {
|
|
15
|
-
getObservable(): BehaviorSubject<string[]>;
|
|
16
|
-
|
|
17
|
-
addItem(item: string): Promise<void>;
|
|
18
|
-
|
|
19
|
-
addItems(items: string[]): Promise<void>;
|
|
20
|
-
|
|
21
|
-
setSelectedItems(items: string[]): Promise<void>;
|
|
22
|
-
|
|
23
|
-
removeItem(item: string): Promise<void>;
|
|
24
|
-
|
|
25
|
-
removeItems(items: string[]): Promise<void>;
|
|
26
|
-
|
|
27
|
-
removeAllItems(): Promise<void>;
|
|
28
|
-
|
|
29
|
-
getSelectedItems(): string[];
|
|
30
|
-
|
|
31
|
-
getSelectedAsync(): Promise<string[]>;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export class StorageMultiSelectProvider implements MultiSelectProvider {
|
|
35
|
-
// TODO: Unsubscribe and remove when there is no listeners
|
|
36
|
-
private static multiSelectProviders: Record<
|
|
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
|
-
);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return this.multiSelectProviders[keyNamespace];
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
private itemSubject: BehaviorSubject<string[] | null>;
|
|
52
|
-
|
|
53
|
-
private readonly key: string;
|
|
54
|
-
private readonly namespace: string;
|
|
55
|
-
|
|
56
|
-
private constructor(keyNamespace: string) {
|
|
57
|
-
const { namespace, key } = getNamespaceAndKey(keyNamespace);
|
|
58
|
-
|
|
59
|
-
if (!key) {
|
|
60
|
-
throw new Error("StorageMultiSelectProvider: Key is required");
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
this.key = key;
|
|
64
|
-
this.namespace = namespace;
|
|
65
|
-
localStorage.addListener?.({ key, namespace }, this.reloadItems);
|
|
66
|
-
|
|
67
|
-
this.itemSubject = new BehaviorSubject([]);
|
|
68
|
-
|
|
69
|
-
void this.getSelectedAsync();
|
|
70
|
-
log_debug("StorageMultiSelectProvider: Initializing");
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
private reloadItems = async ({ value }: StorageListenerArgs) => {
|
|
74
|
-
const selectedItems = value ? value.split(",") : [];
|
|
75
|
-
|
|
76
|
-
log_debug(
|
|
77
|
-
`reloadItems: request to reload items for value: ${value}`,
|
|
78
|
-
selectedItems
|
|
79
|
-
);
|
|
80
|
-
|
|
81
|
-
this.itemSubject.next(selectedItems);
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
public getObservable = (): BehaviorSubject<string[]> => this.itemSubject;
|
|
85
|
-
|
|
86
|
-
private async getSetOfCurrentItems() {
|
|
87
|
-
const currentResult: string = await localStorage.getItem(
|
|
88
|
-
this.key,
|
|
89
|
-
this.namespace
|
|
90
|
-
);
|
|
91
|
-
|
|
92
|
-
return new Set(currentResult ? currentResult.split(",") : []);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
private async updateItemsAndNotifyObservers(currentItems: Set<string>) {
|
|
96
|
-
const arrayOfItems = Array.from(currentItems);
|
|
97
|
-
const newValue = arrayOfItems.join(",");
|
|
98
|
-
await localStorage.setItem(this.key, newValue, this.namespace);
|
|
99
|
-
|
|
100
|
-
this.itemSubject.next(arrayOfItems);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
public addItem = async (item: string): Promise<void> => {
|
|
104
|
-
const currentItems = await this.getSetOfCurrentItems();
|
|
105
|
-
currentItems.add(item);
|
|
106
|
-
log_debug(`addItem: Adding new item: ${item}`);
|
|
107
|
-
|
|
108
|
-
await this.updateItemsAndNotifyObservers(currentItems);
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
public addItems = async (items: string[]): Promise<void> => {
|
|
112
|
-
const currentItems = await this.getSetOfCurrentItems();
|
|
113
|
-
|
|
114
|
-
items.forEach((item) => currentItems.add(item));
|
|
115
|
-
|
|
116
|
-
log_debug(
|
|
117
|
-
`addItems: Adding new items: ${items.join(
|
|
118
|
-
","
|
|
119
|
-
)}, current items: ${Array.from(currentItems).join(",")}`
|
|
120
|
-
);
|
|
121
|
-
|
|
122
|
-
await this.updateItemsAndNotifyObservers(currentItems);
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
public removeItem = async (item: string): Promise<void> => {
|
|
126
|
-
const currentItems = await this.getSetOfCurrentItems();
|
|
127
|
-
currentItems.delete(item);
|
|
128
|
-
|
|
129
|
-
log_debug(
|
|
130
|
-
`removeItem: Removing item: ${item}, current items: ${Array.from(
|
|
131
|
-
currentItems
|
|
132
|
-
).join(",")}`
|
|
133
|
-
);
|
|
134
|
-
|
|
135
|
-
await this.updateItemsAndNotifyObservers(currentItems);
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
public removeItems = async (items: string[]): Promise<void> => {
|
|
139
|
-
const currentItems = await this.getSetOfCurrentItems();
|
|
140
|
-
|
|
141
|
-
items.forEach((item) => currentItems.delete(item));
|
|
142
|
-
|
|
143
|
-
log_debug(
|
|
144
|
-
`removeItems: Removing items: ${items.join(
|
|
145
|
-
","
|
|
146
|
-
)}, current items: ${Array.from(currentItems).join(",")}`
|
|
147
|
-
);
|
|
148
|
-
|
|
149
|
-
await this.updateItemsAndNotifyObservers(currentItems);
|
|
150
|
-
};
|
|
151
|
-
|
|
152
|
-
public removeAllItems = async (): Promise<void> => {
|
|
153
|
-
await localStorage.removeItem(this.key, this.namespace);
|
|
154
|
-
log_debug(`removeAllItems: Removing all items, current items: ${[]}`);
|
|
155
|
-
|
|
156
|
-
this.itemSubject.next([]);
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
public getSelectedAsync = async (): Promise<string[]> => {
|
|
160
|
-
const value = await localStorage.getItem(this.key, this.namespace);
|
|
161
|
-
const selectedItems = value ? value.split(",") : [];
|
|
162
|
-
this.itemSubject.next(selectedItems);
|
|
163
|
-
|
|
164
|
-
return selectedItems;
|
|
165
|
-
};
|
|
166
|
-
|
|
167
|
-
public getSelectedItems = (): string[] => {
|
|
168
|
-
return this.itemSubject.getValue();
|
|
169
|
-
};
|
|
170
|
-
|
|
171
|
-
setSelectedItems = async (items: string[]): Promise<void> => {
|
|
172
|
-
log_debug(`setSelectedItems: Setting selected items: ${items.join(",")}`);
|
|
173
|
-
|
|
174
|
-
await this.updateItemsAndNotifyObservers(new Set(items));
|
|
175
|
-
};
|
|
176
|
-
}
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import { createLogger } from "@applicaster/zapp-react-native-utils/logger";
|
|
2
|
-
import { bridgeLogger } from "../logger";
|
|
3
|
-
import { BehaviorSubject } from "rxjs";
|
|
4
|
-
import { localStorage } from "@applicaster/zapp-react-native-bridge/ZappStorage/LocalStorage";
|
|
5
|
-
import { getNamespaceAndKey } from "@applicaster/zapp-react-native-utils/appUtils/contextKeysManager/utils";
|
|
6
|
-
|
|
7
|
-
export const { log_verbose, log_debug, log_warning, log_info, log_error } =
|
|
8
|
-
createLogger({
|
|
9
|
-
category: "StorageSingleValueProvider",
|
|
10
|
-
subsystem: "zapp-react-native-bridge",
|
|
11
|
-
parent: bridgeLogger,
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
export interface SingleValueProvider {
|
|
15
|
-
getObservable(): BehaviorSubject<string | null>;
|
|
16
|
-
|
|
17
|
-
setValue(value: string): Promise<void>;
|
|
18
|
-
getValue(): string | null;
|
|
19
|
-
getValueAsync(): Promise<string | null>;
|
|
20
|
-
clearValue(): Promise<void>;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
interface StorageListenerArgs {
|
|
24
|
-
value: string | null;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export class StorageSingleValueProvider implements SingleValueProvider {
|
|
28
|
-
// Static cache of providers by namespace
|
|
29
|
-
private static singleValueProviders: Record<
|
|
30
|
-
string,
|
|
31
|
-
StorageSingleValueProvider
|
|
32
|
-
> = {};
|
|
33
|
-
|
|
34
|
-
public static getProvider(keyNamespace: string): StorageSingleValueProvider {
|
|
35
|
-
if (!this.singleValueProviders[keyNamespace]) {
|
|
36
|
-
this.singleValueProviders[keyNamespace] = new StorageSingleValueProvider(
|
|
37
|
-
keyNamespace
|
|
38
|
-
);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return this.singleValueProviders[keyNamespace];
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
private valueSubject: BehaviorSubject<string | null>;
|
|
45
|
-
|
|
46
|
-
private readonly key: string;
|
|
47
|
-
private readonly namespace: string;
|
|
48
|
-
|
|
49
|
-
private constructor(keyNamespace: string) {
|
|
50
|
-
const { namespace, key } = getNamespaceAndKey(keyNamespace);
|
|
51
|
-
|
|
52
|
-
if (!key) {
|
|
53
|
-
throw new Error("StorageSingleValueProvider: Key is required");
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
this.key = key;
|
|
57
|
-
this.namespace = namespace;
|
|
58
|
-
localStorage.addListener?.({ key, namespace }, this.reloadValue);
|
|
59
|
-
|
|
60
|
-
this.valueSubject = new BehaviorSubject<string | null>(null);
|
|
61
|
-
|
|
62
|
-
void this.getValueAsync();
|
|
63
|
-
log_debug("StorageSingleValueProvider: Initializing");
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
private reloadValue = async ({ value }: StorageListenerArgs) => {
|
|
67
|
-
log_debug(`reloadValue: request to reload value: ${value}`);
|
|
68
|
-
|
|
69
|
-
this.valueSubject.next(value);
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
public getObservable = (): BehaviorSubject<string | null> =>
|
|
73
|
-
this.valueSubject;
|
|
74
|
-
|
|
75
|
-
private async updateValueAndNotifyObservers(value: string | null) {
|
|
76
|
-
if (value === null) {
|
|
77
|
-
await localStorage.removeItem(this.key, this.namespace);
|
|
78
|
-
} else {
|
|
79
|
-
await localStorage.setItem(this.key, value, this.namespace);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
this.valueSubject.next(value);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
public setValue = async (value: string): Promise<void> => {
|
|
86
|
-
log_debug(`setValue: Setting new value: ${value}`);
|
|
87
|
-
|
|
88
|
-
await this.updateValueAndNotifyObservers(value);
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
public clearValue = async (): Promise<void> => {
|
|
92
|
-
await localStorage.removeItem(this.key, this.namespace);
|
|
93
|
-
log_debug("clearValue: Removing value");
|
|
94
|
-
|
|
95
|
-
this.valueSubject.next(null);
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
public getValueAsync = async (): Promise<string | null> => {
|
|
99
|
-
const value = await localStorage.getItem(this.key, this.namespace);
|
|
100
|
-
this.valueSubject.next(value);
|
|
101
|
-
|
|
102
|
-
return value;
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
public getValue = (): string | null => {
|
|
106
|
-
return this.valueSubject.getValue();
|
|
107
|
-
};
|
|
108
|
-
}
|