elegance-js 1.15.0 → 1.15.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/package.json +1 -1
- package/scripts/bootstrap.js +61 -0
package/package.json
CHANGED
package/scripts/bootstrap.js
CHANGED
|
@@ -69,6 +69,20 @@ loadHook(
|
|
|
69
69
|
*/
|
|
70
70
|
export const isDynamicPage = true;
|
|
71
71
|
|
|
72
|
+
/*
|
|
73
|
+
This is a request hook,
|
|
74
|
+
it's available for pages with isDynamicPage set to true.
|
|
75
|
+
|
|
76
|
+
It acts a little bit like a middleware.
|
|
77
|
+
The function is called *before* the page is served.
|
|
78
|
+
If you end the request in the hook, the page won't be served.
|
|
79
|
+
|
|
80
|
+
export const requestHook = (req: http.IncomingMessage, res: http.ServerResponse) => {
|
|
81
|
+
res.statusCode = 403;
|
|
82
|
+
res.end();
|
|
83
|
+
};
|
|
84
|
+
*/
|
|
85
|
+
|
|
72
86
|
/*
|
|
73
87
|
State can also be an array!
|
|
74
88
|
In which case, the reactiveMap() method is added onto the state.
|
|
@@ -90,6 +104,53 @@ const ReactiveMap = () => {
|
|
|
90
104
|
})
|
|
91
105
|
};
|
|
92
106
|
|
|
107
|
+
const SlowComponent = () => {
|
|
108
|
+
const myMessage = state<string | undefined>(undefined);
|
|
109
|
+
|
|
110
|
+
loadHook(
|
|
111
|
+
[myMessage],
|
|
112
|
+
(_, message) => {
|
|
113
|
+
setTimeout(() => {
|
|
114
|
+
message.value = "Hello World!";
|
|
115
|
+
message.signal()
|
|
116
|
+
}, 2000);
|
|
117
|
+
},
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
/*
|
|
121
|
+
This is a Barrier component.
|
|
122
|
+
|
|
123
|
+
You can use it to guard clause components in the browser.
|
|
124
|
+
|
|
125
|
+
This is useful for when you for example fetch data in the browser,
|
|
126
|
+
and are waiting for it to resolve.
|
|
127
|
+
|
|
128
|
+
Whilst you're waiting, you can display a loading component,
|
|
129
|
+
instead of blocking the entire page loading.
|
|
130
|
+
|
|
131
|
+
Whenever any value in the dependency array changes,
|
|
132
|
+
the component is re-evaluated.
|
|
133
|
+
*/
|
|
134
|
+
return Barrier(
|
|
135
|
+
[myMessage],
|
|
136
|
+
(message) => {
|
|
137
|
+
if (message === undefined) {
|
|
138
|
+
return div({
|
|
139
|
+
class: "animate-pulse",
|
|
140
|
+
},
|
|
141
|
+
"Loading..",
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return div({
|
|
146
|
+
class: "animate-bounce",
|
|
147
|
+
},
|
|
148
|
+
message
|
|
149
|
+
);
|
|
150
|
+
},
|
|
151
|
+
)
|
|
152
|
+
};
|
|
153
|
+
|
|
93
154
|
/*
|
|
94
155
|
This is the actual content of the page.
|
|
95
156
|
|