riot-history-manager 3.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/README.md +70 -0
- package/dist/index+libs.d.ts +14 -0
- package/dist/index+libs.js +3383 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.es+libs.d.ts +14 -0
- package/dist/index.es+libs.js +3355 -0
- package/dist/index.es.d.ts +14 -0
- package/dist/index.es.js +736 -0
- package/dist/index.js +763 -0
- package/package.json +30 -0
- package/src/constants.ts +12 -0
- package/src/custom-event-handling.ts +266 -0
- package/src/globals.d.ts +6 -0
- package/src/index.ts +24 -0
- package/src/loading-bar.ts +156 -0
- package/src/rhm-navigate.riot +76 -0
- package/src/rhm-route.riot +213 -0
- package/src/rhm-router.riot +77 -0
package/README.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# [riot](https://riot.js.org/) wrapper for [history-manager](https://www.npmjs.com/package/history-manager)
|
|
2
|
+
|
|
3
|
+
## Installation
|
|
4
|
+
```npm install riot-history-manager```
|
|
5
|
+
|
|
6
|
+
## Usage
|
|
7
|
+
index.js
|
|
8
|
+
```js
|
|
9
|
+
import "riot-history-manager";
|
|
10
|
+
|
|
11
|
+
// any code here
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
main.riot
|
|
15
|
+
```riot
|
|
16
|
+
<main>
|
|
17
|
+
<router>
|
|
18
|
+
<route path="" redirect="home" />
|
|
19
|
+
<route path="home">
|
|
20
|
+
<span>HOME</span>
|
|
21
|
+
</route>
|
|
22
|
+
<route path="page1">
|
|
23
|
+
<span>PAGE 1</span>
|
|
24
|
+
<img src="img.jpg" need-loading>
|
|
25
|
+
</route>
|
|
26
|
+
</router>
|
|
27
|
+
|
|
28
|
+
<script>
|
|
29
|
+
import { Router } from "history-manager";
|
|
30
|
+
|
|
31
|
+
Router.setContext({
|
|
32
|
+
// ...
|
|
33
|
+
});
|
|
34
|
+
Router.setContext({
|
|
35
|
+
// ...
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
export default {
|
|
39
|
+
onMounted() {
|
|
40
|
+
Router.start()
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
</script>
|
|
44
|
+
</main>
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Routing cycle
|
|
48
|
+
As soon as the Router calls the `route` component listener, the latter mounts the `slot` in a child div element.
|
|
49
|
+
|
|
50
|
+
In this stage there is the [mount cycle of riot](https://riot.js.org/documentation/#lifecycle-callbacks).
|
|
51
|
+
|
|
52
|
+
Just after this the div element is set with `display: none` until the loading is complete, so you should consider this in any operation started in the mount cycle.
|
|
53
|
+
|
|
54
|
+
Now is dispatched the "beforeroute" event in every newly created element.
|
|
55
|
+
|
|
56
|
+
The `route` now is waiting all the `need-loading` elements to fire the "load" event.
|
|
57
|
+
|
|
58
|
+
When all they are done, it will dispatch the "unroute" event to the previous `route` - if any - and then `unmount`ed it.
|
|
59
|
+
|
|
60
|
+
Now the div element containing the `slot` is set with `display: block` and is dispatched the event "route".
|
|
61
|
+
|
|
62
|
+
Following a more concise explanation:
|
|
63
|
+
1. currentRoute.mount()
|
|
64
|
+
2. `display: none`
|
|
65
|
+
3. currentRoute.dispatchToChildren("beforeroute")
|
|
66
|
+
4. waiting "load" from `need-loading` elements
|
|
67
|
+
5. previousRoute.dispatchToChildren("unroute")
|
|
68
|
+
6. previousRoute.unmount()
|
|
69
|
+
7. `display: block`
|
|
70
|
+
8. currentRoute.dispatchToChildren("route")
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
declare namespace loadingBar {
|
|
2
|
+
function claim(claimer: any): void;
|
|
3
|
+
function claimedBy(claimer: any): boolean;
|
|
4
|
+
const claimed: typeof claimedBy;
|
|
5
|
+
function release(claimer: any): void;
|
|
6
|
+
function isLoading(): boolean;
|
|
7
|
+
function setColor(color: string): void;
|
|
8
|
+
}
|
|
9
|
+
declare const components: {
|
|
10
|
+
RhmNavigate: any;
|
|
11
|
+
RhmRouter: any;
|
|
12
|
+
RhmRoute: any;
|
|
13
|
+
};
|
|
14
|
+
export { components, loadingBar };
|