@unsetsoft/ryunixjs 0.5.8 → 0.5.9-nightly.10
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/Ryunix.js +26 -0
- package/package.json +1 -1
- package/src/lib/hooks.js +34 -1
- package/src/lib/index.js +11 -1
- package/src/main.js +1 -0
package/dist/Ryunix.js
CHANGED
|
@@ -303,6 +303,31 @@
|
|
|
303
303
|
return useMemo(() => callback, deps)
|
|
304
304
|
};
|
|
305
305
|
|
|
306
|
+
const useRouter = (routes) => {
|
|
307
|
+
const [location, setLocation] = useStore(window.location.pathname);
|
|
308
|
+
|
|
309
|
+
const navigate = (path) => {
|
|
310
|
+
window.history.pushState({}, '', path);
|
|
311
|
+
setLocation(path);
|
|
312
|
+
};
|
|
313
|
+
|
|
314
|
+
useEffect(() => {
|
|
315
|
+
const onPopState = () => {
|
|
316
|
+
setLocation(window.location.pathname);
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
window.addEventListener('popstate', onPopState);
|
|
320
|
+
return () => {
|
|
321
|
+
window.removeEventListener('popstate', onPopState);
|
|
322
|
+
}
|
|
323
|
+
}, []);
|
|
324
|
+
|
|
325
|
+
const currentRoute = routes.find((route) => route.path === location);
|
|
326
|
+
const Children = () => (currentRoute ? currentRoute.component : null);
|
|
327
|
+
|
|
328
|
+
return { Children, navigate }
|
|
329
|
+
};
|
|
330
|
+
|
|
306
331
|
const isEvent = (key) => key.startsWith('on');
|
|
307
332
|
const isProperty = (key) => key !== STRINGS.children && !isEvent(key);
|
|
308
333
|
const isNew = (prev, next) => (key) => prev[key] !== next[key];
|
|
@@ -704,6 +729,7 @@
|
|
|
704
729
|
exports.useMemo = useMemo;
|
|
705
730
|
exports.useQuery = useQuery;
|
|
706
731
|
exports.useRef = useRef;
|
|
732
|
+
exports.useRouter = useRouter;
|
|
707
733
|
exports.useStore = useStore;
|
|
708
734
|
|
|
709
735
|
Object.defineProperty(exports, '__esModule', { value: true });
|
package/package.json
CHANGED
package/src/lib/hooks.js
CHANGED
|
@@ -166,4 +166,37 @@ const useCallback = (callback, deps) => {
|
|
|
166
166
|
return useMemo(() => callback, deps)
|
|
167
167
|
}
|
|
168
168
|
|
|
169
|
-
|
|
169
|
+
const useRouter = (routes) => {
|
|
170
|
+
const [location, setLocation] = useStore(window.location.pathname)
|
|
171
|
+
|
|
172
|
+
const navigate = (path) => {
|
|
173
|
+
window.history.pushState({}, '', path)
|
|
174
|
+
setLocation(path)
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
useEffect(() => {
|
|
178
|
+
const onPopState = () => {
|
|
179
|
+
setLocation(window.location.pathname)
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
window.addEventListener('popstate', onPopState)
|
|
183
|
+
return () => {
|
|
184
|
+
window.removeEventListener('popstate', onPopState)
|
|
185
|
+
}
|
|
186
|
+
}, [])
|
|
187
|
+
|
|
188
|
+
const currentRoute = routes.find((route) => route.path === location)
|
|
189
|
+
const Children = () => (currentRoute ? currentRoute.component : null)
|
|
190
|
+
|
|
191
|
+
return { Children, navigate }
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export {
|
|
195
|
+
useStore,
|
|
196
|
+
useEffect,
|
|
197
|
+
useQuery,
|
|
198
|
+
useRef,
|
|
199
|
+
useMemo,
|
|
200
|
+
useCallback,
|
|
201
|
+
useRouter,
|
|
202
|
+
}
|
package/src/lib/index.js
CHANGED
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
useRef,
|
|
8
8
|
useMemo,
|
|
9
9
|
useCallback,
|
|
10
|
+
useRouter,
|
|
10
11
|
} from './hooks'
|
|
11
12
|
import * as Dom from './dom'
|
|
12
13
|
import * as Workers from './workers'
|
|
@@ -14,7 +15,16 @@ import * as Reconciler from './reconciler'
|
|
|
14
15
|
import * as Components from './components'
|
|
15
16
|
import * as Commits from './commits'
|
|
16
17
|
|
|
17
|
-
export {
|
|
18
|
+
export {
|
|
19
|
+
useStore,
|
|
20
|
+
useEffect,
|
|
21
|
+
useQuery,
|
|
22
|
+
useRef,
|
|
23
|
+
useMemo,
|
|
24
|
+
useCallback,
|
|
25
|
+
useRouter,
|
|
26
|
+
Fragment,
|
|
27
|
+
}
|
|
18
28
|
|
|
19
29
|
export default {
|
|
20
30
|
createElement,
|