plug-code 1.2.0 → 2.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 +135 -94
- package/dist/core/helpers/core.d.ts +2 -0
- package/dist/core/helpers/core.js +32 -0
- package/dist/core/hooks/plcHooks.d.ts +15 -0
- package/dist/core/hooks/plcHooks.js +47 -0
- package/dist/core/plcAPI.d.ts +83 -0
- package/dist/core/plcAPI.js +472 -0
- package/dist/core/plcPipeline.d.ts +8 -0
- package/dist/core/plcPipeline.js +35 -0
- package/dist/core/plcScheduler.d.ts +7 -0
- package/dist/core/plcScheduler.js +22 -0
- package/dist/core/plcStore.d.ts +33 -0
- package/dist/core/plcStore.js +159 -0
- package/dist/core/ui/plcCore.d.ts +8 -0
- package/dist/core/ui/plcCore.js +40 -0
- package/dist/core/ui/plcErrorBoundary.d.ts +17 -0
- package/dist/core/ui/plcErrorBoundary.js +17 -0
- package/dist/core/ui/plcInspector.d.ts +5 -0
- package/dist/core/ui/plcInspector.js +27 -0
- package/dist/core/ui/plcLayout.d.ts +28 -0
- package/dist/core/ui/plcLayout.js +125 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +8 -0
- package/dist/types/core/api.d.ts +7 -0
- package/dist/types/core/api.js +1 -0
- package/dist/types/core/general.d.ts +15 -0
- package/dist/types/core/general.js +1 -0
- package/dist/types/core/registry.d.ts +7 -0
- package/dist/types/core/registry.js +1 -0
- package/dist/types/core/ui.d.ts +7 -0
- package/dist/types/core/ui.js +1 -0
- package/dist/types/registry.d.ts +20 -0
- package/dist/types/registry.js +1 -0
- package/package.json +16 -22
- package/index.d.ts +0 -1
- package/src/contexts/pipeline.tsx +0 -4
- package/src/core/plcAPI.tsx +0 -393
- package/src/core/plcPipeline.tsx +0 -87
- package/src/core/plcStore.tsx +0 -94
- package/src/helpers/core.ts +0 -10
- package/src/plug-code.tsx +0 -64
- package/src/types/api.ts +0 -8
- package/src/types/features.ts +0 -7
- package/src/types/general.ts +0 -2
- package/src/types/pipeline.ts +0 -3
- package/src/types/registry.ts +0 -4
- package/src/types/store.ts +0 -2
- package/tsconfig.json +0 -15
- package/types/plug-code.d.ts +0 -164
package/README.md
CHANGED
|
@@ -1,35 +1,77 @@
|
|
|
1
|
-
# 🔌 Plug&Code
|
|
2
1
|
|
|
3
|
-
|
|
4
|
-
It empowers developers to build complex applications by **plugging in independent feature modules** without tightly coupling the codebase.
|
|
2
|
+
# 🔌 Plug&Code (v2)
|
|
5
3
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
[](https://www.npmjs.com/package/plug-code)
|
|
5
|
+
[](LICENSE)
|
|
6
|
+
[](https://www.typescriptlang.org/)
|
|
7
|
+
|
|
8
|
+
**Plug&Code** is a **high-performance**, strongly-typed, **modular React framework**.
|
|
9
|
+
It’s designed for complex enterprise apps (Dashboards, CRMs, ERPs), decoupling **logic**, **UI**, and **data** via a **Feature-based architecture**.
|
|
10
|
+
|
|
11
|
+
> **v2 Highlights:** Full TypeScript support (Generics & Registry Pattern), native virtualization, immutable state management with Immer, and lazy-loaded modules.
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## 🚀 Key Features
|
|
16
|
+
|
|
17
|
+
- 🛡️ **Strong Typing:** Autocomplete and type inference in **Stores**, **Commands**, and **Slots** via the Registry pattern.
|
|
18
|
+
- 🧩 **Feature-First Architecture:** Organize code in portable `ModuleManifests` that encapsulate **state**, **logic**, and **UI**.
|
|
19
|
+
- ⚡ **Native Performance:** Built-in virtual rendering (`markVirtual`) and priority management via **Scheduler**.
|
|
20
|
+
- 🧠 **Reactive State Machine:** Global & module-level state with **Immer** and granular subscriptions.
|
|
21
|
+
- 🎨 **UI Composition Pipeline:** Slots system with **multiple injections**, **priorities**, and **keepAlive** support.
|
|
9
22
|
|
|
10
23
|
---
|
|
11
24
|
|
|
12
25
|
## 📦 Installation
|
|
13
26
|
|
|
27
|
+
<details>
|
|
28
|
+
<summary>Click to expand</summary>
|
|
29
|
+
|
|
14
30
|
```bash
|
|
15
|
-
npm install plug-code
|
|
31
|
+
npm install plug-code immer
|
|
16
32
|
# or
|
|
17
|
-
yarn add plug-code
|
|
18
|
-
|
|
33
|
+
yarn add plug-code immer
|
|
34
|
+
````
|
|
35
|
+
|
|
36
|
+
</details>
|
|
19
37
|
|
|
20
38
|
---
|
|
21
39
|
|
|
22
|
-
##
|
|
40
|
+
## 🛡️ The Type Contract (Registry)
|
|
41
|
+
|
|
42
|
+
Plug&Code requires defining the **shape of your app** in a central registry file, enabling **IntelliSense** everywhere.
|
|
43
|
+
|
|
44
|
+
<details>
|
|
45
|
+
<summary>Example: types/registry.ts</summary>
|
|
23
46
|
|
|
24
|
-
|
|
47
|
+
```ts
|
|
48
|
+
export type User = { id: string; name: string };
|
|
49
|
+
|
|
50
|
+
// 1. App State
|
|
51
|
+
export interface RootStoreRegistry {
|
|
52
|
+
"users:list": User[];
|
|
53
|
+
"app:loading": boolean;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// 2. Commands (Payload -> Result)
|
|
57
|
+
export interface CommandRegistry {
|
|
58
|
+
"users:add": { payload: User; result: void };
|
|
59
|
+
"users:delete": { payload: { id: string }; result: boolean };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// 3. UI Slots
|
|
63
|
+
export interface SlotRegistry {
|
|
64
|
+
"main-layout": {};
|
|
65
|
+
"sidebar": { collapsed: boolean };
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// 4. Feature State
|
|
69
|
+
export interface FeatureRegistry {
|
|
70
|
+
"auth": { token: string | null };
|
|
71
|
+
}
|
|
72
|
+
```
|
|
25
73
|
|
|
26
|
-
|
|
27
|
-
| ----------------------- | -------------------------------------------------------- |
|
|
28
|
-
| **Features** | Independent modules that encapsulate logic, UI, and data |
|
|
29
|
-
| **Stores (State)** | Isolated substores with reactive linking |
|
|
30
|
-
| **Slots (UI Pipeline)** | Injection points for UI from any feature |
|
|
31
|
-
| **Commands (Logic)** | Executable business actions with middleware |
|
|
32
|
-
| **Transforms (Data)** | Data pipelines modified by multiple features |
|
|
74
|
+
</details>
|
|
33
75
|
|
|
34
76
|
---
|
|
35
77
|
|
|
@@ -37,115 +79,114 @@ Plug&Code is built around the **PLC (Pipeline–Logic–Command)** pattern combi
|
|
|
37
79
|
|
|
38
80
|
### 1️⃣ Create a Feature Module
|
|
39
81
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
import type { PlcAPI } from 'plug-code';
|
|
43
|
-
|
|
44
|
-
export const PaginationFeature = (api: PlcAPI<any>) => {
|
|
45
|
-
api.createData("pagination", { currentPage: 1, pageSize: 10, total: 0 });
|
|
82
|
+
<details>
|
|
83
|
+
<summary>Example: UsersFeature</summary>
|
|
46
84
|
|
|
47
|
-
|
|
85
|
+
```ts
|
|
86
|
+
import { ModuleManifest } from 'plug-code';
|
|
87
|
+
import { useCommand, useStore } from '../framework/plcHooks';
|
|
48
88
|
|
|
49
|
-
|
|
50
|
-
|
|
89
|
+
const UserList = () => {
|
|
90
|
+
const users = useStore("users:list", s => s);
|
|
91
|
+
const deleteCmd = useCommand("users:delete");
|
|
51
92
|
|
|
52
|
-
|
|
93
|
+
return (
|
|
94
|
+
<ul>
|
|
95
|
+
{users.map(u => (
|
|
96
|
+
<li key={u.id}>
|
|
97
|
+
{u.name} <button onClick={() => deleteCmd({ id: u.id })}>x</button>
|
|
98
|
+
</li>
|
|
99
|
+
))}
|
|
100
|
+
</ul>
|
|
101
|
+
);
|
|
102
|
+
};
|
|
53
103
|
|
|
54
|
-
|
|
55
|
-
|
|
104
|
+
export const UsersFeature: ModuleManifest = {
|
|
105
|
+
name: "users",
|
|
106
|
+
state: { "users:list": [] },
|
|
107
|
+
commands: {
|
|
108
|
+
"users:delete": ({ id }) => {
|
|
109
|
+
console.log("Deleting", id);
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
slots: {
|
|
114
|
+
"main-layout": [{ id: "user-list-view", component: UserList, priority: 10 }]
|
|
115
|
+
},
|
|
116
|
+
onLoad: (api) => {
|
|
117
|
+
api.markVirtual("main-layout", { itemHeight: 50 });
|
|
118
|
+
}
|
|
56
119
|
};
|
|
57
120
|
```
|
|
58
121
|
|
|
122
|
+
</details>
|
|
123
|
+
|
|
59
124
|
---
|
|
60
125
|
|
|
61
126
|
### 2️⃣ Initialize the System
|
|
62
127
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
import { createPlugAndCode } from 'plug-code';
|
|
66
|
-
import { PaginationFeature } from './features/PaginationFeature';
|
|
67
|
-
import { SalesFeature } from './features/SalesFeature';
|
|
68
|
-
|
|
69
|
-
export const { useSystemPlc, SystemPlcRoot } = createPlugAndCode((api) => {
|
|
70
|
-
// It creates root automatically | root = {}
|
|
71
|
-
PaginationFeature(api);
|
|
72
|
-
SalesFeature(api);
|
|
73
|
-
});
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
---
|
|
128
|
+
<details>
|
|
129
|
+
<summary>Example: main.tsx</summary>
|
|
77
130
|
|
|
78
|
-
|
|
131
|
+
```ts
|
|
132
|
+
import { PlcStore, PlcAPI, PlcProvider } from 'plug-code';
|
|
133
|
+
import { UsersFeature } from './features/UsersFeature';
|
|
79
134
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
import { useSystemPlc, SystemPlcRoot } from './system';
|
|
135
|
+
const store = new PlcStore();
|
|
136
|
+
const api = new PlcAPI(store);
|
|
83
137
|
|
|
84
|
-
|
|
85
|
-
const { api, useSelector } = useSystemPlc({ mode: "production" });
|
|
138
|
+
api.registerModule(UsersFeature);
|
|
86
139
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
</main>
|
|
95
|
-
</SystemPlcRoot>
|
|
96
|
-
);
|
|
97
|
-
}
|
|
140
|
+
const App = () => (
|
|
141
|
+
<PlcProvider api={api}>
|
|
142
|
+
<div className="app">
|
|
143
|
+
{api.render("main-layout")}
|
|
144
|
+
</div>
|
|
145
|
+
</PlcProvider>
|
|
146
|
+
);
|
|
98
147
|
```
|
|
99
148
|
|
|
149
|
+
</details>
|
|
150
|
+
|
|
100
151
|
---
|
|
101
152
|
|
|
102
153
|
## 📚 API Reference
|
|
103
154
|
|
|
104
|
-
### 🧬 State
|
|
155
|
+
### 🧬 State Management (`api`)
|
|
105
156
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
| `update(key, updater, slot?, trigger?)` | Mutate store using Immer |
|
|
111
|
-
| `derive(target, deps, calc)` | Create reactive linkage |
|
|
112
|
-
| `watch(key, selector, cb)` | Listen to store changes |
|
|
157
|
+
* `createStore<K>(key, initial)`: Initialize a key in the root store.
|
|
158
|
+
* `setStore<K>(key, updater, priority?, useTransition?)`: Update state using **Immer**. Supports React 18 concurrency.
|
|
159
|
+
* `getStore<K>(key)`: Get a snapshot of the state.
|
|
160
|
+
* `watch<K>(key, selector, callback)`: Listen to reactive changes outside components.
|
|
113
161
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
### 🎨 UI Slots
|
|
162
|
+
### 🎨 UI & Layout (`api.layout`)
|
|
117
163
|
|
|
118
|
-
|
|
119
|
-
| ------------------------------------ | -------------------- |
|
|
120
|
-
| `register(slot, component, depKey?)` | Attach UI to slot |
|
|
121
|
-
| `render(slot, props?)` | Render slot pipeline |
|
|
164
|
+
* `register(slot, id, component, priority, keepAlive)`: Inject a component in a slot.
|
|
122
165
|
|
|
123
|
-
|
|
166
|
+
* `priority`: higher number = higher placement.
|
|
167
|
+
* `keepAlive`: keeps the component in memory (hidden DOM) between view changes.
|
|
168
|
+
* `render(slot, props)`: Render slot content.
|
|
169
|
+
* `markVirtual(slot, config)`: Transform a slot into a **high-performance virtual list** (supports 10k+ items).
|
|
124
170
|
|
|
125
|
-
### 🧠
|
|
171
|
+
### 🧠 Logic & Commands
|
|
126
172
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
| `execute(id, payload)` | Run command |
|
|
131
|
-
| `wrapCommand(id, middleware)` | Intercept command |
|
|
132
|
-
|
|
133
|
-
---
|
|
173
|
+
* `registerCommand(id, fn)`: Register a global command.
|
|
174
|
+
* `execute(id, payload)`: Execute a command and return a typed Promise.
|
|
175
|
+
* `wrapCommand(id, middleware)`: Intercept commands (logging, confirmation, etc).
|
|
134
176
|
|
|
135
|
-
###
|
|
177
|
+
### ⚛️ React Hooks
|
|
136
178
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
| `receive(channel, data)` | Run pipeline |
|
|
179
|
+
* `useStore(key, selector)`: Reactive, selective state subscription.
|
|
180
|
+
* `useCommand(id)`: Get an executable command function.
|
|
181
|
+
* `useSlot(slot)`: Render a slot dynamically.
|
|
141
182
|
|
|
142
183
|
---
|
|
143
184
|
|
|
144
185
|
## 🌟 Best Practices
|
|
145
186
|
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
187
|
+
* **Define types first:** Everything starts in `registry.ts`.
|
|
188
|
+
* **Atomic Features:** A feature should contain all it needs (Store, UI, Commands).
|
|
189
|
+
* **Data-Driven UI:** Change the store, let watchers/hooks update the view.
|
|
190
|
+
* **Use Virtualization:** For large or growing lists, call `api.markVirtual` in `onLoad`.
|
|
150
191
|
|
|
151
192
|
---
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export function isEqual(a, b) {
|
|
2
|
+
if (a === b)
|
|
3
|
+
return true;
|
|
4
|
+
if (typeof a !== typeof b)
|
|
5
|
+
return false;
|
|
6
|
+
if (typeof a !== 'object' || !a || !b)
|
|
7
|
+
return false;
|
|
8
|
+
const keysA = Object.keys(a);
|
|
9
|
+
const keysB = Object.keys(b);
|
|
10
|
+
if (keysA.length !== keysB.length)
|
|
11
|
+
return false;
|
|
12
|
+
for (const key of keysA) {
|
|
13
|
+
if (a[key] !== b[key])
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
export function shallowCompare(obj1, obj2) {
|
|
19
|
+
if (obj1 === obj2)
|
|
20
|
+
return true;
|
|
21
|
+
if (!obj1 || !obj2)
|
|
22
|
+
return false;
|
|
23
|
+
const keys1 = Object.keys(obj1);
|
|
24
|
+
const keys2 = Object.keys(obj2);
|
|
25
|
+
if (keys1.length !== keys2.length)
|
|
26
|
+
return false;
|
|
27
|
+
for (const key of keys1) {
|
|
28
|
+
if (obj1[key] !== obj2[key])
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { PlcAPI } from "../plcAPI";
|
|
3
|
+
import { StoreKey, StoreValue, CommandKey, CmdPayload, CmdResult, SlotKey, SlotProps, FeatureRegistry, FeatureKey } from "../../types/registry";
|
|
4
|
+
type SafeFeatureValue<F, K> = F extends keyof FeatureRegistry ? (K extends keyof FeatureRegistry[F] ? FeatureRegistry[F][K] : any) : any;
|
|
5
|
+
export declare const PlcProvider: React.FC<{
|
|
6
|
+
api: PlcAPI;
|
|
7
|
+
children: React.ReactNode;
|
|
8
|
+
}>;
|
|
9
|
+
export declare function useStore<K extends StoreKey, T = StoreValue<K>>(key: K, selector?: (data: StoreValue<K>) => T): T;
|
|
10
|
+
export declare function useStore<F extends FeatureKey, K extends keyof SafeFeatureValue<F, K> & string, T = SafeFeatureValue<F, K>>(key: `${F}:${K}`, selector?: (data: SafeFeatureValue<F, K>) => T): T;
|
|
11
|
+
export declare function useCommand<K extends CommandKey>(commandId: K): (payload?: CmdPayload<K>) => Promise<CmdResult<K>>;
|
|
12
|
+
export declare function useSlot<K extends SlotKey>(slotName: K): (props?: SlotProps<K>) => React.ReactNode;
|
|
13
|
+
export declare function useTransientStore<K extends StoreKey, T>(key: K, selector: (state: StoreValue<K>) => T, effect: (value: T) => void, deps?: any[]): void;
|
|
14
|
+
export declare function useTransientStore<F extends FeatureKey, K extends keyof SafeFeatureValue<F, K> & string, T>(key: `${F}:${K}`, selector: (state: SafeFeatureValue<F, K>) => T, effect: (value: T) => void, deps?: any[]): void;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useContext, useEffect, useMemo, useState } from "react";
|
|
3
|
+
const PlcContext = createContext(null);
|
|
4
|
+
export const PlcProvider = ({ api, children }) => {
|
|
5
|
+
return _jsx(PlcContext.Provider, { value: api, children: children });
|
|
6
|
+
};
|
|
7
|
+
const usePlcApi = () => {
|
|
8
|
+
const api = useContext(PlcContext);
|
|
9
|
+
if (!api)
|
|
10
|
+
throw new Error("usePlcApi must be used within a PlcProvider");
|
|
11
|
+
return api;
|
|
12
|
+
};
|
|
13
|
+
export function useStore(key, selector = (d) => d) {
|
|
14
|
+
const api = usePlcApi();
|
|
15
|
+
const [value, setValue] = useState(() => {
|
|
16
|
+
const storeVal = key.includes(":")
|
|
17
|
+
? api.getSubstore(...key.split(":"))
|
|
18
|
+
: api.getStore(key);
|
|
19
|
+
return selector(storeVal);
|
|
20
|
+
});
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
const unsubscribe = api.watch(key, selector, (newValue) => {
|
|
23
|
+
setValue(newValue);
|
|
24
|
+
});
|
|
25
|
+
return unsubscribe;
|
|
26
|
+
}, [api, key, selector]);
|
|
27
|
+
return value;
|
|
28
|
+
}
|
|
29
|
+
export function useCommand(commandId) {
|
|
30
|
+
const api = usePlcApi();
|
|
31
|
+
return useMemo(() => {
|
|
32
|
+
return (payload) => api.execute(commandId, payload);
|
|
33
|
+
}, [api, commandId]);
|
|
34
|
+
}
|
|
35
|
+
export function useSlot(slotName) {
|
|
36
|
+
const api = usePlcApi();
|
|
37
|
+
return (props) => api.render(slotName, props);
|
|
38
|
+
}
|
|
39
|
+
export function useTransientStore(key, selector, effect, deps = []) {
|
|
40
|
+
const api = usePlcApi();
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
const unsubscribe = api.watch(key, selector, (newValue) => {
|
|
43
|
+
effect(newValue);
|
|
44
|
+
});
|
|
45
|
+
return unsubscribe;
|
|
46
|
+
}, [api, key, ...deps]);
|
|
47
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { CommandFn } from "../types/core/api";
|
|
3
|
+
import { ModuleManifest } from "../types/core/general";
|
|
4
|
+
import { PlcStore } from "./plcStore";
|
|
5
|
+
import { Priority } from "./plcScheduler";
|
|
6
|
+
import { Draft } from "immer";
|
|
7
|
+
import { PlcLayout } from "./ui/plcLayout";
|
|
8
|
+
import { SlotWrapper } from "../types/core/ui";
|
|
9
|
+
import { CommandRegistry, FeatureRegistry, StoreKey, CommandKey, SlotKey, FeatureKey, StoreValue, SlotProps } from "../types/registry";
|
|
10
|
+
type SafeCmdPayload<K> = K extends keyof CommandRegistry ? (CommandRegistry[K] extends {
|
|
11
|
+
payload: infer P;
|
|
12
|
+
} ? P : void) : any;
|
|
13
|
+
type SafeCmdResult<K> = K extends keyof CommandRegistry ? (CommandRegistry[K] extends {
|
|
14
|
+
result: infer R;
|
|
15
|
+
} ? R : void) : any;
|
|
16
|
+
type SafeFeatureValue<F, K> = F extends keyof FeatureRegistry ? (K extends keyof FeatureRegistry[F] ? FeatureRegistry[F][K] : any) : any;
|
|
17
|
+
export declare class PlcAPI {
|
|
18
|
+
private store;
|
|
19
|
+
private pipeline;
|
|
20
|
+
private scheduler;
|
|
21
|
+
layout: PlcLayout;
|
|
22
|
+
private compiledPipelines;
|
|
23
|
+
private receiveCache;
|
|
24
|
+
private commands;
|
|
25
|
+
private activeDependencyTracker;
|
|
26
|
+
private loadedFeatures;
|
|
27
|
+
constructor(store: PlcStore);
|
|
28
|
+
createStore<K extends StoreKey>(key: K, initial: StoreValue<K>): void;
|
|
29
|
+
getStore<K extends StoreKey>(key: K): StoreValue<K>;
|
|
30
|
+
setStore<K extends StoreKey>(key: K, updater: StoreValue<K> | ((draft: Draft<StoreValue<K>>) => void | StoreValue<K>), priority?: Priority, useTransition?: boolean): void;
|
|
31
|
+
createSubstore<F extends FeatureKey, K extends keyof any>(substore: F, key: K, initial: SafeFeatureValue<F, K>): void;
|
|
32
|
+
getSubstore<F extends FeatureKey, K extends keyof any>(substore: F, key: K): SafeFeatureValue<F, K>;
|
|
33
|
+
setSubstore<F extends FeatureKey, K extends keyof any>(substore: F, key: K, updater: SafeFeatureValue<F, K> | ((draft: Draft<SafeFeatureValue<F, K>>) => void | SafeFeatureValue<F, K>), priority?: Priority, useTransition?: boolean): void;
|
|
34
|
+
protected recordDependency(key: string, value: any): void;
|
|
35
|
+
makeTransform<T = any>(channel: string, id: string, fn: (data: T, ctx: any) => T | Promise<T>, priority?: number): void;
|
|
36
|
+
getTransform<T = any>(channel: string, initialData: T, context?: any, opts?: {
|
|
37
|
+
equality?: 'identity' | 'shallow' | 'deep';
|
|
38
|
+
}): Promise<T>;
|
|
39
|
+
receive<K extends string>(channel: K, initialData: any, context?: any): any;
|
|
40
|
+
registerCommand<K extends CommandKey>(id: K, fn: (payload?: SafeCmdPayload<K>) => SafeCmdResult<K> | Promise<SafeCmdResult<K>>): void;
|
|
41
|
+
wrapCommand<K extends CommandKey>(id: K, wrapper: (next: CommandFn<SafeCmdPayload<K>, SafeCmdResult<K>>) => CommandFn<SafeCmdPayload<K>, SafeCmdResult<K>>): void;
|
|
42
|
+
execute<K extends CommandKey>(id: K, payload?: SafeCmdPayload<K>): Promise<SafeCmdResult<K>>;
|
|
43
|
+
deriveStore<K extends StoreKey, Output>(outputKey: K, outputSlot: StoreKey, dependencies: StoreKey[], calculator: (...args: any[]) => Output): {
|
|
44
|
+
getValue: () => any;
|
|
45
|
+
trigger: () => void;
|
|
46
|
+
dispose: () => void;
|
|
47
|
+
};
|
|
48
|
+
deriveSubstore<F extends FeatureKey, K extends keyof any, Output>(substore: F, outputKey: K, outputSlot: keyof any, dependencies: string[], calculator: (...args: any[]) => Output): {
|
|
49
|
+
getValue: () => any;
|
|
50
|
+
trigger: () => void;
|
|
51
|
+
dispose: () => void;
|
|
52
|
+
};
|
|
53
|
+
private _triggerVersion;
|
|
54
|
+
private bumpVersion;
|
|
55
|
+
watch<K extends StoreKey, T>(key: K, selector: (data: StoreValue<K>) => T, callback: (newValue: T, oldValue: T) => void): () => void;
|
|
56
|
+
watch<F extends FeatureKey, K extends keyof any, T>(key: `${F}:${string & K}`, selector: (data: SafeFeatureValue<F, K>) => T, callback: (newValue: T, oldValue: T) => void): () => void;
|
|
57
|
+
watchStore<T>(storeKey: string, selector: (data: any) => T, callback: (newValue: T, oldValue: T) => void): () => void;
|
|
58
|
+
watchSubstore<T>(substore: string, key: string, selector: (data: any) => T, callback: (newValue: T, oldValue: T) => void): () => void;
|
|
59
|
+
watchAllStores<T = any>(definitions: Array<{
|
|
60
|
+
substore?: string;
|
|
61
|
+
store: string;
|
|
62
|
+
selector: (data: any) => Partial<T>;
|
|
63
|
+
}>, callback: (newValues: T, oldValues: T) => void): () => void;
|
|
64
|
+
redraw(keyOrSlot: string): void;
|
|
65
|
+
register<K extends SlotKey>(slot: K, id: string, componentFn: (props?: SlotProps<K>) => React.ReactNode, priority?: number, keepAlive?: boolean): void;
|
|
66
|
+
wrap<K extends SlotKey>(slot: K, wrapper: SlotWrapper): void;
|
|
67
|
+
after<K extends SlotKey>(slot: K, targetId: string, newId: string, componentFn: () => React.ReactNode): void;
|
|
68
|
+
render<K extends SlotKey>(slot: K, props?: SlotProps<K>): React.ReactNode;
|
|
69
|
+
markVirtual(slot: SlotKey, config?: {
|
|
70
|
+
itemHeight?: number;
|
|
71
|
+
overscan?: number;
|
|
72
|
+
}): void;
|
|
73
|
+
connect(renderFn: (props?: any) => React.ReactNode, dependencies: Array<string | {
|
|
74
|
+
store: string;
|
|
75
|
+
keys?: string[];
|
|
76
|
+
}>): React.FC<any>;
|
|
77
|
+
registerModule(manifest: ModuleManifest): void;
|
|
78
|
+
loadFeature(importer: () => Promise<{
|
|
79
|
+
default: ModuleManifest;
|
|
80
|
+
}>): Promise<void>;
|
|
81
|
+
createSelector<S, R>(extractor: (state: S) => any[], calculator: (...args: any[]) => R): (state: S) => R;
|
|
82
|
+
}
|
|
83
|
+
export {};
|