lilact 0.2.2 → 0.3.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/lilact.development.min.js +2 -9617
- package/dist/lilact.development.min.js.LICENSE.txt +1 -1
- package/dist/lilact.development.min.js.map +1 -1
- package/dist/lilact.production.min.js +1 -8139
- package/dist/lilact.production.min.js.map +1 -1
- package/docs/assets/navigation.js +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/functions/hooks.forwardRef.html +1 -1
- package/docs/functions/hooks.useImperativeHandle.html +1 -1
- package/docs/functions/redux.combineReducers.html +12 -0
- package/docs/functions/redux.connect.html +1 -1
- package/docs/functions/timers.animationFramePromise.html +1 -1
- package/docs/functions/timers.clearInterval.html +1 -1
- package/docs/functions/timers.clearTimeout.html +1 -1
- package/docs/functions/timers.grabTimers.html +1 -1
- package/docs/functions/timers.pauseTimers.html +1 -1
- package/docs/functions/timers.releaseTimers.html +1 -1
- package/docs/functions/timers.resetTimers.html +1 -1
- package/docs/functions/timers.resumeTimers.html +1 -1
- package/docs/functions/timers.setInterval.html +1 -1
- package/docs/functions/timers.setTimeout.html +1 -1
- package/docs/functions/timers.timeoutPromise.html +1 -1
- package/docs/modules/redux.html +1 -1
- package/docs/static/lilact.development.min.js +2 -9617
- package/docs/static/lilact.production.min.js +1 -8139
- package/package.json +1 -1
- package/root/lilact.development.min.js +2 -9617
- package/root/lilact.production.min.js +1 -8139
- package/src/hooks.jsx +1 -2
- package/src/lilact.jsx +3 -7
- package/src/redux.jsx +60 -55
- package/src/timers.jsx +7 -2
- package/webpack.config.js +1 -1
package/src/hooks.jsx
CHANGED
|
@@ -407,7 +407,7 @@ export function useReducer(reducer, initialArg, init)
|
|
|
407
407
|
|
|
408
408
|
|
|
409
409
|
|
|
410
|
-
// todo: very simple implementation. not lilactish! must be modified
|
|
410
|
+
// todo: very simple implementation. and not lilactish at all! must be modified
|
|
411
411
|
|
|
412
412
|
/**
|
|
413
413
|
* Returns a deferred value that updates later than the provided input.
|
|
@@ -417,7 +417,6 @@ export function useReducer(reducer, initialArg, init)
|
|
|
417
417
|
*/
|
|
418
418
|
export function useDeferredValue(value, initialValue)
|
|
419
419
|
{
|
|
420
|
-
|
|
421
420
|
const { useEffect, useRef, useState } = Lilact;
|
|
422
421
|
|
|
423
422
|
const [deferred, setDeferred] = useState(
|
package/src/lilact.jsx
CHANGED
|
@@ -51,7 +51,6 @@ import {ResizablePane} from './pane.jsx';
|
|
|
51
51
|
|
|
52
52
|
import {transpileJSX, transpilerConfig} from "./jsx";
|
|
53
53
|
|
|
54
|
-
//import '../node_modules/@dragdroptouch/drag-drop-touch/dist/drag-drop-touch.esm.min.js';
|
|
55
54
|
|
|
56
55
|
|
|
57
56
|
/**
|
|
@@ -64,13 +63,13 @@ import {transpileJSX, transpilerConfig} from "./jsx";
|
|
|
64
63
|
export const Lilact =
|
|
65
64
|
{
|
|
66
65
|
|
|
67
|
-
VERSION: "beta.
|
|
66
|
+
VERSION: "beta.3",
|
|
68
67
|
|
|
69
68
|
// Configuration
|
|
70
69
|
|
|
71
70
|
defaultTransitionTimeout: 300,
|
|
72
71
|
defaultIsEqual: Object.is, // note: `Lilact.shallowEqual` and `Lilact.deepEqual` are also available,
|
|
73
|
-
|
|
72
|
+
// user can set it in your initializer code, and can be changed later too.
|
|
74
73
|
|
|
75
74
|
// Units
|
|
76
75
|
|
|
@@ -82,7 +81,6 @@ export const Lilact =
|
|
|
82
81
|
...timers,
|
|
83
82
|
...misc,
|
|
84
83
|
...EventWrapper,
|
|
85
|
-
//...db,
|
|
86
84
|
|
|
87
85
|
...router,
|
|
88
86
|
...accessories,
|
|
@@ -92,10 +90,8 @@ export const Lilact =
|
|
|
92
90
|
transpileJSX,
|
|
93
91
|
transpilerConfig,
|
|
94
92
|
|
|
95
|
-
// Dependencies
|
|
96
|
-
|
|
93
|
+
// Dependencies
|
|
97
94
|
PropTypes,
|
|
98
|
-
//redux: {...redux, createSlice, createAsyncThunk},
|
|
99
95
|
redux,
|
|
100
96
|
emotion,
|
|
101
97
|
|
package/src/redux.jsx
CHANGED
|
@@ -81,68 +81,35 @@ export function useDispatch()
|
|
|
81
81
|
* @param [equalityFn=(a, b) => a === b] - Determines when the selected value should update.
|
|
82
82
|
* @returns The selected slice of state.
|
|
83
83
|
*/
|
|
84
|
-
export function useSelector(selector, equalityFn = (a, b) => a === b)
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
const [, forceRender] = Lilact.useState(0);
|
|
90
|
-
|
|
91
|
-
if (!latestSelectorRef.current) {
|
|
92
|
-
latestSelectorRef.current = selector;
|
|
93
|
-
}
|
|
94
|
-
latestSelectorRef.current = selector;
|
|
95
|
-
|
|
96
|
-
let selected = selector(store.getState()); // todo: should exception be covered?
|
|
84
|
+
export function useSelector(selector, equalityFn = (a, b) => a === b) {
|
|
85
|
+
const store = Lilact.useStore();
|
|
86
|
+
const latestSelected = Lilact.useRef();
|
|
87
|
+
const selectorRef = Lilact.useRef(selector);
|
|
88
|
+
selectorRef.current = selector;
|
|
97
89
|
|
|
98
|
-
|
|
99
|
-
latestSelectedRef.current = selected;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
Lilact.useLayoutEffect(() => {
|
|
103
|
-
// keep latestSelectedRef in sync after render (in case selector used props or similar)
|
|
104
|
-
latestSelectedRef.current = selected;
|
|
105
|
-
}, [selected]);
|
|
90
|
+
const [selected, setSelected] = Lilact.useState(() => selector(store.getState()));
|
|
106
91
|
|
|
107
|
-
|
|
92
|
+
// Keep ref in sync for the subscription callback
|
|
93
|
+
latestSelected.current = selected;
|
|
108
94
|
|
|
109
|
-
|
|
95
|
+
Lilact.useEffect(() => {
|
|
96
|
+
function checkForUpdates() {
|
|
97
|
+
const nextSelected = selectorRef.current(store.getState());
|
|
98
|
+
if (!equalityFn(latestSelected.current, nextSelected)) {
|
|
99
|
+
latestSelected.current = nextSelected;
|
|
100
|
+
setSelected(nextSelected);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
110
103
|
|
|
111
|
-
|
|
112
|
-
if (didUnsubscribe) return;
|
|
113
|
-
try {
|
|
114
|
-
const newSelected = latestSelectorRef.current(store.getState());
|
|
115
|
-
const oldSelected = latestSelectedRef.current;
|
|
116
|
-
if (!equalityFn(oldSelected, newSelected)) {
|
|
117
|
-
latestSelectedRef.current = newSelected;
|
|
104
|
+
const unsubscribe = store.subscribe(checkForUpdates);
|
|
118
105
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
} catch (err) {
|
|
106
|
+
// In case state changed between render and effect
|
|
107
|
+
checkForUpdates();
|
|
122
108
|
|
|
123
|
-
|
|
124
|
-
|
|
109
|
+
return unsubscribe;
|
|
110
|
+
}, [store, equalityFn]);
|
|
125
111
|
|
|
126
|
-
|
|
127
|
-
// (could instead log or ignore)
|
|
128
|
-
// throw err;
|
|
129
|
-
console.warn(err);
|
|
130
|
-
ʔ }
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
const unsubscribe = store.subscribe(checkForUpdates);
|
|
135
|
-
|
|
136
|
-
// run check once in case state changed between render and effect
|
|
137
|
-
checkForUpdates();
|
|
138
|
-
|
|
139
|
-
return () => {
|
|
140
|
-
didUnsubscribe = true;
|
|
141
|
-
unsubscribe();
|
|
142
|
-
};
|
|
143
|
-
}, [store, equalityFn]);
|
|
144
|
-
|
|
145
|
-
return latestSelectedRef.current;
|
|
112
|
+
return selected;
|
|
146
113
|
}
|
|
147
114
|
|
|
148
115
|
|
|
@@ -196,3 +163,41 @@ export function connect(mapStateToProps, mapDispatchToProps)
|
|
|
196
163
|
};
|
|
197
164
|
}
|
|
198
165
|
|
|
166
|
+
/**
|
|
167
|
+
* Creates a root reducer by mapping keys to slice reducers.
|
|
168
|
+
*
|
|
169
|
+
* Each slice reducer is called with:
|
|
170
|
+
* - the previous slice state at `state[key]` (or `undefined` initially)
|
|
171
|
+
* - the dispatched action
|
|
172
|
+
*
|
|
173
|
+
* The returned reducer builds the next state object using all reducer keys.
|
|
174
|
+
* If none of the slice reducers produce a change (reference equality),
|
|
175
|
+
* the previous `state` object is returned to avoid unnecessary updates.
|
|
176
|
+
*
|
|
177
|
+
* @param {object} reducers - An object whose values are reducers.
|
|
178
|
+
* @returns {function} A root reducer function compatible with your createStore.
|
|
179
|
+
*/
|
|
180
|
+
export function combineReducers(reducers) {
|
|
181
|
+
const reducerKeys = Object.keys(reducers);
|
|
182
|
+
|
|
183
|
+
for (const key of reducerKeys) {
|
|
184
|
+
if (typeof reducers[key] !== "function") {
|
|
185
|
+
throw new Error(`combineReducers: reducer for key "${key}" is not a function`);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
return function rootReducer(state = {}, action) {
|
|
190
|
+
let hasChanged = false;
|
|
191
|
+
const nextState = {};
|
|
192
|
+
|
|
193
|
+
for (const key of reducerKeys) {
|
|
194
|
+
const reducer = reducers[key];
|
|
195
|
+
const prevSlice = state[key];
|
|
196
|
+
const nextSlice = reducer(prevSlice, action);
|
|
197
|
+
nextState[key] = nextSlice;
|
|
198
|
+
hasChanged = hasChanged || nextSlice !== prevSlice;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
return hasChanged ? nextState : state;
|
|
202
|
+
};
|
|
203
|
+
}
|
package/src/timers.jsx
CHANGED
|
@@ -38,11 +38,16 @@
|
|
|
38
38
|
/**
|
|
39
39
|
* Timer helpers for a promise-friendly timer framework.
|
|
40
40
|
*
|
|
41
|
-
* These functions keep the same call signatures as the standard JavaScript timer APIs where applicable
|
|
41
|
+
* These functions keep the same call signatures as the standard JavaScript timer APIs where applicable
|
|
42
|
+
* (`setTimeout`/`setInterval`/`clearTimeout`/`clearInterval`),
|
|
43
|
+
* but add extra capabilities for promise-friendly control and lifecycle management.
|
|
44
|
+
*
|
|
45
|
+
* This module can “grab” timers and later pause/resume/reset/release them, plus provide promise wrappers
|
|
46
|
+
* like `timeoutPromise` and `animationFramePromise`.
|
|
42
47
|
*
|
|
43
48
|
* - `setTimeout` / `setInterval`: schedule callbacks (same interface as the built-ins).
|
|
44
49
|
* - `clearTimeout` / `clearInterval`: cancel scheduled timers (same interface as the built-ins).
|
|
45
|
-
* - `grabTimers` / `pauseTimers` / `resumeTimers` / `resetTimers` / `releaseTimers`: manage tracked timers
|
|
50
|
+
* - `grabTimers` / `pauseTimers` / `resumeTimers` / `resetTimers` / `releaseTimers`: manage tracked timers.
|
|
46
51
|
* - `timeoutPromise` / `animationFramePromise`: promise-based convenience wrappers.
|
|
47
52
|
*/
|
|
48
53
|
|
package/webpack.config.js
CHANGED
|
@@ -56,7 +56,7 @@ export default (env, argv) => {
|
|
|
56
56
|
optimization: {
|
|
57
57
|
concatenateModules: true, // scope hoisting
|
|
58
58
|
moduleIds: 'deterministic', // smaller stable ids (or 'hashed')
|
|
59
|
-
minimize:
|
|
59
|
+
minimize: true //mode === 'production',
|
|
60
60
|
},
|
|
61
61
|
experiments: {
|
|
62
62
|
outputModule: true // enable module output
|