@streamlayer/sdk-web-interfaces 0.0.1
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 +6 -0
- package/lib/auth.d.ts +6 -0
- package/lib/auth.js +2 -0
- package/lib/feature.d.ts +44 -0
- package/lib/feature.js +91 -0
- package/lib/index.d.ts +17 -0
- package/lib/index.js +6 -0
- package/lib/store/abstract.d.ts +45 -0
- package/lib/store/abstract.js +84 -0
- package/lib/store/api.d.ts +21 -0
- package/lib/store/api.js +62 -0
- package/lib/store/map.d.ts +19 -0
- package/lib/store/map.js +36 -0
- package/lib/store/single.d.ts +19 -0
- package/lib/store/single.js +39 -0
- package/package.json +29 -0
package/README.md
ADDED
package/lib/auth.d.ts
ADDED
package/lib/auth.js
ADDED
package/lib/feature.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { FeatureConfig as SdkOverlay, SdkOverlaySettings } from '@streamlayer/sdk-web-types';
|
|
2
|
+
import { PlainMessage } from '@bufbuild/protobuf';
|
|
3
|
+
import { WritableAtom } from 'nanostores';
|
|
4
|
+
import { MapStore } from './store/map';
|
|
5
|
+
type FeatureListener = {
|
|
6
|
+
name: string;
|
|
7
|
+
enabled: boolean;
|
|
8
|
+
onEvent: (...args: unknown[]) => void;
|
|
9
|
+
};
|
|
10
|
+
export type FeatureProps = PlainMessage<SdkOverlay>;
|
|
11
|
+
export declare enum FeatureSource {
|
|
12
|
+
ORGANIZATION = "ORGANIZATION",
|
|
13
|
+
STREAM = "STREAM"
|
|
14
|
+
}
|
|
15
|
+
type FeatureConfig = Omit<FeatureProps, 'settings'>;
|
|
16
|
+
type FeatureSettings = Exclude<PlainMessage<SdkOverlaySettings>['overlaySettings'], {
|
|
17
|
+
case: 'inplay';
|
|
18
|
+
} | {
|
|
19
|
+
case: 'getstream';
|
|
20
|
+
} | {
|
|
21
|
+
case: undefined;
|
|
22
|
+
}>;
|
|
23
|
+
export declare enum FeatureStatus {
|
|
24
|
+
Ready = "ready",
|
|
25
|
+
Suspended = "suspended"
|
|
26
|
+
}
|
|
27
|
+
export declare class AbstractFeature<K extends FeatureSettings['case'] | undefined, C extends FeatureSettings['value'] = FeatureSettings['value']> {
|
|
28
|
+
status: WritableAtom<FeatureStatus>;
|
|
29
|
+
source: FeatureSource;
|
|
30
|
+
protected config: MapStore<FeatureConfig>;
|
|
31
|
+
protected settings: MapStore<C>;
|
|
32
|
+
protected listeners: Set<FeatureListener>;
|
|
33
|
+
protected settingsKey: K;
|
|
34
|
+
constructor({ settings, ...config }: FeatureProps, source: FeatureSource);
|
|
35
|
+
get featureConfig(): import("nanostores").MapStore<FeatureConfig>;
|
|
36
|
+
get featureSettings(): import("nanostores").MapStore<C>;
|
|
37
|
+
registerEventListener(listener: FeatureListener): void;
|
|
38
|
+
enable: () => void;
|
|
39
|
+
disable: () => void;
|
|
40
|
+
setFeatureConfig: ({ settings, ...config }: FeatureProps) => void;
|
|
41
|
+
update: (config: FeatureProps, source: FeatureSource) => void;
|
|
42
|
+
protected fireEvent(event: unknown): void;
|
|
43
|
+
}
|
|
44
|
+
export {};
|
package/lib/feature.js
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { FeatureType } from '@streamlayer/sdk-web-types';
|
|
2
|
+
import { atom } from 'nanostores';
|
|
3
|
+
import { createMapStore, MapStore } from './store/map';
|
|
4
|
+
export var FeatureSource;
|
|
5
|
+
(function (FeatureSource) {
|
|
6
|
+
FeatureSource["ORGANIZATION"] = "ORGANIZATION";
|
|
7
|
+
FeatureSource["STREAM"] = "STREAM";
|
|
8
|
+
})(FeatureSource || (FeatureSource = {}));
|
|
9
|
+
const FeatureTypes = {
|
|
10
|
+
[FeatureType.BETTING]: 'betting',
|
|
11
|
+
[FeatureType.GAMES]: 'games',
|
|
12
|
+
[FeatureType.PUBLIC_CHAT]: 'publicChat',
|
|
13
|
+
[FeatureType.TWITTER]: 'twitter',
|
|
14
|
+
};
|
|
15
|
+
export var FeatureStatus;
|
|
16
|
+
(function (FeatureStatus) {
|
|
17
|
+
FeatureStatus["Ready"] = "ready";
|
|
18
|
+
FeatureStatus["Suspended"] = "suspended";
|
|
19
|
+
})(FeatureStatus || (FeatureStatus = {}));
|
|
20
|
+
export class AbstractFeature {
|
|
21
|
+
status;
|
|
22
|
+
source;
|
|
23
|
+
config;
|
|
24
|
+
settings;
|
|
25
|
+
listeners = new Set();
|
|
26
|
+
settingsKey;
|
|
27
|
+
constructor({ settings, ...config }, source) {
|
|
28
|
+
this.settingsKey = FeatureTypes[config.type];
|
|
29
|
+
this.status = atom(FeatureStatus.Suspended);
|
|
30
|
+
this.config = new MapStore(createMapStore(config), `feature:config:${this.settingsKey}`);
|
|
31
|
+
if (this.settingsKey !== undefined && settings?.overlaySettings.case === this.settingsKey) {
|
|
32
|
+
this.settings = new MapStore(createMapStore(settings.overlaySettings.value), `feature:settings:${this.settingsKey}`);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
this.settings = new MapStore(createMapStore({}), `feature:settings:${this.settingsKey}`);
|
|
36
|
+
}
|
|
37
|
+
this.source = source;
|
|
38
|
+
}
|
|
39
|
+
get featureConfig() {
|
|
40
|
+
return this.config.getStore();
|
|
41
|
+
}
|
|
42
|
+
get featureSettings() {
|
|
43
|
+
return this.settings.getStore();
|
|
44
|
+
}
|
|
45
|
+
registerEventListener(listener) {
|
|
46
|
+
this.listeners.add(listener);
|
|
47
|
+
}
|
|
48
|
+
enable = () => {
|
|
49
|
+
this.status.set(FeatureStatus.Ready);
|
|
50
|
+
};
|
|
51
|
+
disable = () => {
|
|
52
|
+
this.status.set(FeatureStatus.Suspended);
|
|
53
|
+
};
|
|
54
|
+
setFeatureConfig = ({ settings, ...config }) => {
|
|
55
|
+
let configKey;
|
|
56
|
+
for (configKey in config) {
|
|
57
|
+
this.config.setValue(configKey, config[configKey]);
|
|
58
|
+
}
|
|
59
|
+
if (settings?.overlaySettings?.case !== undefined && settings?.overlaySettings.case === this.settingsKey) {
|
|
60
|
+
const newSettings = settings.overlaySettings.value;
|
|
61
|
+
if (newSettings !== undefined) {
|
|
62
|
+
let key;
|
|
63
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
64
|
+
// @ts-ignore
|
|
65
|
+
for (key in newSettings) {
|
|
66
|
+
console.log(key, newSettings[key]);
|
|
67
|
+
if (newSettings[key] !== 0 && newSettings[key] !== '') {
|
|
68
|
+
this.settings.setValue(key, newSettings[key]);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
update = (config, source) => {
|
|
75
|
+
if (this.source === FeatureSource.STREAM && source === FeatureSource.ORGANIZATION) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
this.setFeatureConfig(config);
|
|
79
|
+
this.source = source;
|
|
80
|
+
};
|
|
81
|
+
fireEvent(event) {
|
|
82
|
+
for (const listener of this.listeners.values()) {
|
|
83
|
+
try {
|
|
84
|
+
listener.onEvent(event);
|
|
85
|
+
}
|
|
86
|
+
catch (err) {
|
|
87
|
+
console.error(err);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { FeatureType } from '@streamlayer/sdk-web-types';
|
|
2
|
+
export { AbstractAuthenticationProvider } from './auth';
|
|
3
|
+
export { AbstractFeature, FeatureSource, type FeatureProps, FeatureStatus } from './feature';
|
|
4
|
+
export { MapStore, createMapStore } from './store/map';
|
|
5
|
+
export type { MapStoreListeners } from './store/map';
|
|
6
|
+
export { SingleStore, createSingleStore, createComputedStore } from './store/single';
|
|
7
|
+
export { AbstractStore, mergeStores } from './store/abstract';
|
|
8
|
+
export { ApiStore } from './store/api';
|
|
9
|
+
export interface StreamLayerSDK {
|
|
10
|
+
openFeature: (featureType: FeatureType) => void;
|
|
11
|
+
closeFeature: () => void;
|
|
12
|
+
}
|
|
13
|
+
export interface StreamLayerContext {
|
|
14
|
+
sdk: StreamLayerSDK;
|
|
15
|
+
}
|
|
16
|
+
type DoneFn = Function;
|
|
17
|
+
export type StreamLayerPlugin = (instance: StreamLayerContext, opts: unknown, done: DoneFn) => void;
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { AbstractAuthenticationProvider } from './auth';
|
|
2
|
+
export { AbstractFeature, FeatureSource, FeatureStatus } from './feature';
|
|
3
|
+
export { MapStore, createMapStore } from './store/map';
|
|
4
|
+
export { SingleStore, createSingleStore, createComputedStore } from './store/single';
|
|
5
|
+
export { AbstractStore, mergeStores } from './store/abstract';
|
|
6
|
+
export { ApiStore } from './store/api';
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { AnyStore } from 'nanostores';
|
|
2
|
+
declare global {
|
|
3
|
+
interface Window {
|
|
4
|
+
slStore: any;
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* An abstract store is a wrapper for third-party stores,
|
|
9
|
+
* providing developers with a consistent interface inspired
|
|
10
|
+
* by the "nanostore" pattern. This simplifies
|
|
11
|
+
* interactions with different storage systems.
|
|
12
|
+
*/
|
|
13
|
+
export declare abstract class AbstractStore<T extends AnyStore> {
|
|
14
|
+
/**
|
|
15
|
+
* store instance (nanostores)
|
|
16
|
+
*/
|
|
17
|
+
protected readonly store: T;
|
|
18
|
+
protected readonly name: string;
|
|
19
|
+
constructor(store: T, name: string);
|
|
20
|
+
/**
|
|
21
|
+
* return store instance
|
|
22
|
+
*/
|
|
23
|
+
getStore(): T;
|
|
24
|
+
/**
|
|
25
|
+
* get all store values
|
|
26
|
+
*/
|
|
27
|
+
abstract getValues(): unknown;
|
|
28
|
+
/**
|
|
29
|
+
* get store value by key
|
|
30
|
+
*/
|
|
31
|
+
abstract getValue(...args: unknown[]): unknown;
|
|
32
|
+
/**
|
|
33
|
+
* subscribe directly to store changes
|
|
34
|
+
*/
|
|
35
|
+
abstract subscribe(...args: unknown[]): void;
|
|
36
|
+
/**
|
|
37
|
+
* unsubscribe directly to store change
|
|
38
|
+
*/
|
|
39
|
+
abstract unsubscribe(): void;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Merge multiple stores into a single instance using a single
|
|
43
|
+
* subscribe handler, leveraging the `useStore` method from `@nanostores/react` for React subscriptions.
|
|
44
|
+
*/
|
|
45
|
+
export declare const mergeStores: <T extends Record<string, AbstractStore<AnyStore>>, K = { [Index in keyof T]: ReturnType<T[Index]["getStore"]>["value"]; }>(stores: T) => import("nanostores").ReadableAtom<K>;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { computed } from 'nanostores';
|
|
2
|
+
import { buildLogger } from '@nanostores/logger';
|
|
3
|
+
import diff from 'microdiff';
|
|
4
|
+
window.slStore = Object.create(null);
|
|
5
|
+
const slStoreLogger = (store, name) => buildLogger(store, name, {
|
|
6
|
+
mount: ({ storeName }) => {
|
|
7
|
+
if (!window.slStore[storeName]) {
|
|
8
|
+
window.slStore[storeName] = { mounted: true, history: [{ type: 'mount' }] };
|
|
9
|
+
}
|
|
10
|
+
window.slStore[storeName].store = store;
|
|
11
|
+
},
|
|
12
|
+
unmount: ({ storeName }) => {
|
|
13
|
+
window.slStore[storeName].mounted = false;
|
|
14
|
+
window.slStore[storeName]?.history.push({ type: 'unmount' });
|
|
15
|
+
},
|
|
16
|
+
change: ({ actionName, storeName, changed, newValue, oldValue, valueMessage }) => {
|
|
17
|
+
window.slStore[storeName]?.history.push({
|
|
18
|
+
type: 'change',
|
|
19
|
+
changed,
|
|
20
|
+
newValue,
|
|
21
|
+
oldValue,
|
|
22
|
+
diff: diff({ ...oldValue }, { ...newValue }, { cyclesFix: false }),
|
|
23
|
+
actionName,
|
|
24
|
+
valueMessage,
|
|
25
|
+
});
|
|
26
|
+
},
|
|
27
|
+
action: {
|
|
28
|
+
start: ({ actionName, args, storeName }) => {
|
|
29
|
+
window.slStore[storeName]?.history.push({
|
|
30
|
+
type: 'action:start',
|
|
31
|
+
actionName,
|
|
32
|
+
args,
|
|
33
|
+
storeName,
|
|
34
|
+
});
|
|
35
|
+
},
|
|
36
|
+
error: ({ actionName, error, storeName }) => {
|
|
37
|
+
window.slStore[storeName]?.history.push({
|
|
38
|
+
type: 'action:error',
|
|
39
|
+
actionName,
|
|
40
|
+
error,
|
|
41
|
+
});
|
|
42
|
+
},
|
|
43
|
+
end: ({ actionName, storeName }) => {
|
|
44
|
+
window.slStore[storeName]?.history.push({
|
|
45
|
+
type: 'action:end',
|
|
46
|
+
actionName,
|
|
47
|
+
});
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
/**
|
|
52
|
+
* An abstract store is a wrapper for third-party stores,
|
|
53
|
+
* providing developers with a consistent interface inspired
|
|
54
|
+
* by the "nanostore" pattern. This simplifies
|
|
55
|
+
* interactions with different storage systems.
|
|
56
|
+
*/
|
|
57
|
+
export class AbstractStore {
|
|
58
|
+
/**
|
|
59
|
+
* store instance (nanostores)
|
|
60
|
+
*/
|
|
61
|
+
store;
|
|
62
|
+
name;
|
|
63
|
+
constructor(store, name) {
|
|
64
|
+
this.store = store;
|
|
65
|
+
this.name = name;
|
|
66
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
67
|
+
slStoreLogger(this.store, this.name);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* return store instance
|
|
72
|
+
*/
|
|
73
|
+
getStore() {
|
|
74
|
+
return this.store;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Merge multiple stores into a single instance using a single
|
|
79
|
+
* subscribe handler, leveraging the `useStore` method from `@nanostores/react` for React subscriptions.
|
|
80
|
+
*/
|
|
81
|
+
export const mergeStores = (stores) => {
|
|
82
|
+
const storeKeys = Object.keys(stores);
|
|
83
|
+
return computed(storeKeys.map((key) => stores[key].getStore()), (...storeValues) => Object.fromEntries(storeKeys.map((key, i) => [key, storeValues[i]])));
|
|
84
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { FetcherStore, FetcherValue } from '@nanostores/query';
|
|
2
|
+
import { WritableAtom } from 'nanostores';
|
|
3
|
+
import { AbstractStore } from './abstract';
|
|
4
|
+
/**
|
|
5
|
+
* Wrapper for @nanostores/query FetcherStore
|
|
6
|
+
*/
|
|
7
|
+
export declare class ApiStore<StoreValue, StoreInstance extends FetcherStore<StoreValue, any> = FetcherStore<StoreValue, any>> extends AbstractStore<StoreInstance> {
|
|
8
|
+
private readonly atomStore;
|
|
9
|
+
constructor(store: StoreInstance, name: string, atomPicker?: (val: FetcherValue<StoreValue, unknown>, prevVal?: string) => string | undefined);
|
|
10
|
+
getAtomStore: () => WritableAtom<string | undefined>;
|
|
11
|
+
getValue: () => Promise<StoreValue | undefined>;
|
|
12
|
+
getValues: () => never;
|
|
13
|
+
setValue: (value?: StoreInstance['value']) => void;
|
|
14
|
+
subscribe: StoreInstance['subscribe'];
|
|
15
|
+
unsubscribe: () => never;
|
|
16
|
+
invalidate: () => void;
|
|
17
|
+
listen: (cb: Parameters<StoreInstance['listen']>[0]) => () => void;
|
|
18
|
+
get(): void;
|
|
19
|
+
key: () => string | undefined;
|
|
20
|
+
off: () => void;
|
|
21
|
+
}
|
package/lib/store/api.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { atom } from 'nanostores';
|
|
2
|
+
import { AbstractStore } from './abstract';
|
|
3
|
+
/**
|
|
4
|
+
* Wrapper for @nanostores/query FetcherStore
|
|
5
|
+
*/
|
|
6
|
+
export class ApiStore extends AbstractStore {
|
|
7
|
+
atomStore;
|
|
8
|
+
constructor(store, name, atomPicker) {
|
|
9
|
+
super(store, `api:${name}`);
|
|
10
|
+
this.atomStore = atom();
|
|
11
|
+
if (atomPicker) {
|
|
12
|
+
store.subscribe((data) => {
|
|
13
|
+
const prev = this.atomStore.get();
|
|
14
|
+
const newValue = atomPicker(data, prev);
|
|
15
|
+
if (prev !== newValue) {
|
|
16
|
+
this.atomStore.set(newValue);
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
getAtomStore = () => this.atomStore;
|
|
22
|
+
getValue = async () => {
|
|
23
|
+
const store = this.getStore();
|
|
24
|
+
if (store.value === undefined) {
|
|
25
|
+
throw new Error('no store');
|
|
26
|
+
}
|
|
27
|
+
await store.value.promise;
|
|
28
|
+
return store.get().data;
|
|
29
|
+
};
|
|
30
|
+
getValues = () => {
|
|
31
|
+
throw new Error('not implemented');
|
|
32
|
+
};
|
|
33
|
+
setValue = (value) => {
|
|
34
|
+
const store = this.getStore();
|
|
35
|
+
return store.set({ loading: false, data: value?.data });
|
|
36
|
+
};
|
|
37
|
+
subscribe = (listener) => {
|
|
38
|
+
const store = this.getStore();
|
|
39
|
+
return store.subscribe(listener);
|
|
40
|
+
};
|
|
41
|
+
unsubscribe = () => {
|
|
42
|
+
throw new Error('not implemented');
|
|
43
|
+
};
|
|
44
|
+
invalidate = () => {
|
|
45
|
+
this.store.invalidate();
|
|
46
|
+
};
|
|
47
|
+
listen = (cb) => {
|
|
48
|
+
const store = this.getStore();
|
|
49
|
+
return store.listen(cb);
|
|
50
|
+
};
|
|
51
|
+
get() {
|
|
52
|
+
throw new Error('not implemented');
|
|
53
|
+
}
|
|
54
|
+
key = () => {
|
|
55
|
+
const store = this.getStore();
|
|
56
|
+
return store.key;
|
|
57
|
+
};
|
|
58
|
+
off = () => {
|
|
59
|
+
const store = this.getStore();
|
|
60
|
+
return store.off();
|
|
61
|
+
};
|
|
62
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { MapStoreKeys, MapStore as NMapStore } from 'nanostores';
|
|
2
|
+
import { AbstractStore } from './abstract';
|
|
3
|
+
/**
|
|
4
|
+
* Wrapper for nanostores MapStore
|
|
5
|
+
*/
|
|
6
|
+
export declare class MapStore<StoreInterface extends object, StoreInstance extends NMapStore<StoreInterface> = NMapStore<StoreInterface>> extends AbstractStore<StoreInstance> {
|
|
7
|
+
getValues: () => StoreInterface;
|
|
8
|
+
getValue: (key: MapStoreKeys<StoreInstance>) => StoreInterface[MapStoreKeys<StoreInstance>];
|
|
9
|
+
setValue: <Key extends MapStoreKeys<StoreInstance>>(path: Key, value: StoreInterface[Key]) => void;
|
|
10
|
+
subscribe: StoreInstance['subscribe'];
|
|
11
|
+
unsubscribe: () => void;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* create map store from nanostores
|
|
15
|
+
*/
|
|
16
|
+
export declare const createMapStore: <Data extends object>(initialData: Data) => NMapStore<Data>;
|
|
17
|
+
export type MapStoreListeners<StoreInstance extends NMapStore<StoreInterface>, StoreInterface extends object> = {
|
|
18
|
+
[T in MapStoreKeys<StoreInstance>]: (value: StoreInterface[T]) => void;
|
|
19
|
+
};
|
package/lib/store/map.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { map } from 'nanostores';
|
|
2
|
+
import { AbstractStore } from './abstract';
|
|
3
|
+
/**
|
|
4
|
+
* Wrapper for nanostores MapStore
|
|
5
|
+
*/
|
|
6
|
+
export class MapStore extends AbstractStore {
|
|
7
|
+
getValues = () => {
|
|
8
|
+
const store = this.getStore();
|
|
9
|
+
return store.get();
|
|
10
|
+
};
|
|
11
|
+
getValue = (key) => {
|
|
12
|
+
const store = this.getStore();
|
|
13
|
+
return store.get()[key];
|
|
14
|
+
};
|
|
15
|
+
setValue = (path, value) => {
|
|
16
|
+
const store = this.getStore();
|
|
17
|
+
// wrong infer type
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
19
|
+
// @ts-ignore
|
|
20
|
+
return store.setKey(path, value);
|
|
21
|
+
};
|
|
22
|
+
subscribe = (...args) => {
|
|
23
|
+
const store = this.getStore();
|
|
24
|
+
return store.subscribe(...args);
|
|
25
|
+
};
|
|
26
|
+
unsubscribe = () => {
|
|
27
|
+
const store = this.getStore();
|
|
28
|
+
return store.off();
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* create map store from nanostores
|
|
33
|
+
*/
|
|
34
|
+
export const createMapStore = (initialData) => {
|
|
35
|
+
return map(initialData);
|
|
36
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { StoreValue, WritableAtom } from 'nanostores';
|
|
2
|
+
import { AbstractStore } from './abstract';
|
|
3
|
+
/**
|
|
4
|
+
* Wrapper for nanostores WritableAtom
|
|
5
|
+
*/
|
|
6
|
+
export declare class SingleStore<StoreValue, StoreInstance extends WritableAtom<StoreValue | undefined> = WritableAtom<StoreValue | undefined>> extends AbstractStore<StoreInstance> {
|
|
7
|
+
getValue: () => StoreInstance['value'];
|
|
8
|
+
getValues(): unknown;
|
|
9
|
+
setValue: (value?: StoreValue) => void;
|
|
10
|
+
subscribe: (listener: Parameters<StoreInstance['subscribe']>[0]) => () => void;
|
|
11
|
+
unsubscribe: () => void;
|
|
12
|
+
listen(listener: Parameters<StoreInstance['subscribe']>[0]): () => void;
|
|
13
|
+
get(): StoreValue | undefined;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* create atom store from nanostores
|
|
17
|
+
*/
|
|
18
|
+
export declare const createSingleStore: <T>(initialData: T) => WritableAtom<T>;
|
|
19
|
+
export declare const createComputedStore: <Value, T extends WritableAtom<any> = WritableAtom<any>>(store: T, mutator: (value: StoreValue<T>) => Value) => import("nanostores").ReadableAtom<Value>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { atom, computed } from 'nanostores';
|
|
2
|
+
import { AbstractStore } from './abstract';
|
|
3
|
+
/**
|
|
4
|
+
* Wrapper for nanostores WritableAtom
|
|
5
|
+
*/
|
|
6
|
+
export class SingleStore extends AbstractStore {
|
|
7
|
+
getValue = () => {
|
|
8
|
+
const store = this.getStore();
|
|
9
|
+
return store.get();
|
|
10
|
+
};
|
|
11
|
+
getValues() {
|
|
12
|
+
throw new Error('not implemented');
|
|
13
|
+
}
|
|
14
|
+
setValue = (value) => {
|
|
15
|
+
const store = this.getStore();
|
|
16
|
+
return store.set(value);
|
|
17
|
+
};
|
|
18
|
+
subscribe = (listener) => {
|
|
19
|
+
const store = this.getStore();
|
|
20
|
+
return store.subscribe(listener);
|
|
21
|
+
};
|
|
22
|
+
unsubscribe = () => {
|
|
23
|
+
const store = this.getStore();
|
|
24
|
+
return store.off();
|
|
25
|
+
};
|
|
26
|
+
listen(listener) {
|
|
27
|
+
const store = this.getStore();
|
|
28
|
+
return store.listen(listener);
|
|
29
|
+
}
|
|
30
|
+
get() {
|
|
31
|
+
const store = this.getStore();
|
|
32
|
+
return store.get();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* create atom store from nanostores
|
|
37
|
+
*/
|
|
38
|
+
export const createSingleStore = (initialData) => atom(initialData);
|
|
39
|
+
export const createComputedStore = (store, mutator) => computed(store, mutator);
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@streamlayer/sdk-web-interfaces",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./lib/index.js",
|
|
6
|
+
"typings": "./lib/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"lib/",
|
|
9
|
+
"package.json"
|
|
10
|
+
],
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"module": "./lib/index.js",
|
|
14
|
+
"require": "./lib/index.js",
|
|
15
|
+
"types": "./lib/index.d.ts"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"peerDependencies": {
|
|
19
|
+
"@nanostores/logger": "^0.2.4",
|
|
20
|
+
"@nanostores/query": "^0.2.8",
|
|
21
|
+
"nanostores": "^0.9.5",
|
|
22
|
+
"@bufbuild/protobuf": "^1.4.2",
|
|
23
|
+
"microdiff": "^1.3.2",
|
|
24
|
+
"@streamlayer/sdk-web-types": "^0.0.1"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"tslib": "^2.6.2"
|
|
28
|
+
}
|
|
29
|
+
}
|