@blac/react 0.0.3 → 0.0.4-0
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/dist/blac-react.d.ts +43 -3
- package/dist/blac-react.esm.js +10 -2
- package/dist/blac-react.esm.js.map +1 -1
- package/dist/blac-react.js +12 -2
- package/dist/blac-react.js.map +1 -1
- package/package.json +1 -1
package/dist/blac-react.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import { Blac, BlocBase,
|
|
1
|
+
import { Blac, BlocBase, BlocClass, ValueType } from 'blac';
|
|
2
2
|
import React, { FC, ReactNode } from 'react';
|
|
3
3
|
|
|
4
|
-
declare const
|
|
4
|
+
declare const BlacApp: FC<{
|
|
5
|
+
children: JSX.Element;
|
|
6
|
+
blac: Blac<any, any>;
|
|
7
|
+
}>;
|
|
5
8
|
|
|
6
9
|
/**
|
|
7
10
|
* Keep track of the hierarchy of Blac BlocProvider components, so that
|
|
@@ -13,6 +16,42 @@ interface ProviderItem {
|
|
|
13
16
|
parent?: string;
|
|
14
17
|
bloc: BlocBase<any>;
|
|
15
18
|
}
|
|
19
|
+
declare class BlacReact {
|
|
20
|
+
blac: Blac<any, any>;
|
|
21
|
+
blacContext: React.Context<Blac<any, any>>;
|
|
22
|
+
localContextProvider: React.Context<BlocBase<any> | null>;
|
|
23
|
+
static pluginKey: string;
|
|
24
|
+
constructor(blac: Blac<any, any>, blacContext: React.Context<Blac<any, any>>);
|
|
25
|
+
static getInstance(): BlacReact;
|
|
26
|
+
setup(): void;
|
|
27
|
+
/**
|
|
28
|
+
* React hook to get the bloc instance from the nearest BlocProvider
|
|
29
|
+
*/
|
|
30
|
+
useLocalBlocContext(): BlocBase<any> | null;
|
|
31
|
+
private _contextLocalProviderKey;
|
|
32
|
+
get LocalProvider(): React.Provider<string>;
|
|
33
|
+
/**
|
|
34
|
+
* React hook to get the id from the nearest BlocProvider
|
|
35
|
+
*/
|
|
36
|
+
useLocalProviderKey(): string;
|
|
37
|
+
addLocalBloc: (item: ProviderItem) => void;
|
|
38
|
+
removeLocalBloc: (id: string) => void;
|
|
39
|
+
createProviderId: () => string;
|
|
40
|
+
providerList: ProviderItem[];
|
|
41
|
+
getLocalBlocForProvider<B>(id: string, blocClass: BlocClass<B>): BlocBase<B> | undefined;
|
|
42
|
+
providerMounted(options: {
|
|
43
|
+
providerId: string;
|
|
44
|
+
localProviderKey?: string;
|
|
45
|
+
} & Parameters<BlacReact['useLocalProvider']>[0]): {
|
|
46
|
+
instance: BlocBase<any> | undefined;
|
|
47
|
+
destroyOnUnmount: boolean;
|
|
48
|
+
};
|
|
49
|
+
providerUnmounted(providerId: string | undefined): void;
|
|
50
|
+
readonly useLocalProvider: (options: {
|
|
51
|
+
bloc: BlocBase<any> | (() => BlocBase<any>);
|
|
52
|
+
debug?: boolean;
|
|
53
|
+
}) => string | undefined;
|
|
54
|
+
}
|
|
16
55
|
|
|
17
56
|
declare const BlocProvider: FC<{
|
|
18
57
|
children?: ReactNode;
|
|
@@ -25,6 +64,7 @@ interface ExternalStore<B extends BlocBase<any>> {
|
|
|
25
64
|
getSnapshot: () => ValueType<B>;
|
|
26
65
|
getServerSnapshot?: () => ValueType<B>;
|
|
27
66
|
}
|
|
67
|
+
declare const externalBlocStore: <B extends BlocBase<any>>(bloc: B) => ExternalStore<B>;
|
|
28
68
|
|
|
29
69
|
type BlocHookData<B extends BlocBase<S>, S> = [
|
|
30
70
|
value: ValueType<B>,
|
|
@@ -39,4 +79,4 @@ interface BlocHookOptions {
|
|
|
39
79
|
}
|
|
40
80
|
declare const useBloc: <B extends BlocBase<S>, S>(bloc: BlocClass<B> | (() => B), options?: BlocHookOptions) => BlocHookData<B, S>;
|
|
41
81
|
|
|
42
|
-
export {
|
|
82
|
+
export { BlacApp, BlacReact, BlocProvider, ExternalStore, externalBlocStore, useBloc };
|
package/dist/blac-react.esm.js
CHANGED
|
@@ -133,7 +133,15 @@ class BlacReact {
|
|
|
133
133
|
};
|
|
134
134
|
}
|
|
135
135
|
|
|
136
|
-
const BlacContext = createContext(null);
|
|
136
|
+
const BlacContext = createContext(null);
|
|
137
|
+
const BlacApp = (props) => {
|
|
138
|
+
const { children, blac } = props;
|
|
139
|
+
const blacApp = useMemo(() => new BlacReact(blac, BlacContext), [blac]);
|
|
140
|
+
if (!blacApp) {
|
|
141
|
+
throw new Error('BlacReact failed to initialize');
|
|
142
|
+
}
|
|
143
|
+
return React.createElement(BlacContext.Provider, { value: blac }, children);
|
|
144
|
+
};
|
|
137
145
|
|
|
138
146
|
const BlocProvider = ({ children, bloc, debug }) => {
|
|
139
147
|
const blacReact = BlacReact.getInstance();
|
|
@@ -201,5 +209,5 @@ const useBloc = (bloc, options = {}) => {
|
|
|
201
209
|
return [state, resolvedBloc];
|
|
202
210
|
};
|
|
203
211
|
|
|
204
|
-
export {
|
|
212
|
+
export { BlacApp, BlacReact, BlocProvider, externalBlocStore, useBloc };
|
|
205
213
|
//# sourceMappingURL=blac-react.esm.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"blac-react.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"blac-react.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/blac-react.js
CHANGED
|
@@ -135,7 +135,15 @@ class BlacReact {
|
|
|
135
135
|
};
|
|
136
136
|
}
|
|
137
137
|
|
|
138
|
-
const BlacContext = React.createContext(null);
|
|
138
|
+
const BlacContext = React.createContext(null);
|
|
139
|
+
const BlacApp = (props) => {
|
|
140
|
+
const { children, blac } = props;
|
|
141
|
+
const blacApp = React.useMemo(() => new BlacReact(blac, BlacContext), [blac]);
|
|
142
|
+
if (!blacApp) {
|
|
143
|
+
throw new Error('BlacReact failed to initialize');
|
|
144
|
+
}
|
|
145
|
+
return React.createElement(BlacContext.Provider, { value: blac }, children);
|
|
146
|
+
};
|
|
139
147
|
|
|
140
148
|
const BlocProvider = ({ children, bloc, debug }) => {
|
|
141
149
|
const blacReact = BlacReact.getInstance();
|
|
@@ -203,7 +211,9 @@ const useBloc = (bloc, options = {}) => {
|
|
|
203
211
|
return [state, resolvedBloc];
|
|
204
212
|
};
|
|
205
213
|
|
|
206
|
-
exports.
|
|
214
|
+
exports.BlacApp = BlacApp;
|
|
215
|
+
exports.BlacReact = BlacReact;
|
|
207
216
|
exports.BlocProvider = BlocProvider;
|
|
217
|
+
exports.externalBlocStore = externalBlocStore;
|
|
208
218
|
exports.useBloc = useBloc;
|
|
209
219
|
//# sourceMappingURL=blac-react.js.map
|
package/dist/blac-react.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"blac-react.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"blac-react.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|