cradova 1.4.0 → 1.5.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 +58 -28
- package/dist/index.d.ts +41 -53
- package/dist/index.js +963 -995
- package/dist/types.ts +12 -115
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
<
|
|
1
|
+
<div style="display: flex; align-items:center; justify-content: space-around; width: 100%;">
|
|
2
|
+
<h1 style="border: none"> Cradova</h1>
|
|
3
|
+
<a><img src="cradova.png" alt="cradova logo" width="100" height="100"></a>
|
|
4
|
+
</div>
|
|
5
|
+
<br>
|
|
6
|
+
<hr>
|
|
7
|
+
<br>
|
|
8
|
+
<br>
|
|
2
9
|
|
|
3
|
-
# Cradova.js
|
|
4
10
|
[](https://www.npmjs.com/package/cradova)
|
|
5
11
|
[](https://github.com/cradova/cradova.js/blob/next/LICENSE)
|
|
6
12
|
[](https://www.npmjs.com/package/cradova)
|
|
@@ -8,28 +14,33 @@
|
|
|
8
14
|
[](https://opencollective.com/cradova)
|
|
9
15
|
[](https://github.com/cradova/cradova.js/blob/next/contributing.md)
|
|
10
16
|
|
|
11
|
-
|
|
12
17
|
## Contents
|
|
13
18
|
|
|
14
|
-
- [What is Cradova](#what-is-
|
|
15
|
-
- [Why
|
|
19
|
+
- [What is Cradova](#what-is-cradova)
|
|
20
|
+
- [Why Cradova?](#whats-the-benefit)
|
|
16
21
|
- [Installation](#installation)
|
|
17
22
|
- [Examples](#examples)
|
|
18
23
|
- [Documentation](#documentation)
|
|
19
24
|
- [Getting Help](#getting-help)
|
|
20
25
|
- [Contributing](#contributing)
|
|
21
26
|
|
|
22
|
-
## What is
|
|
27
|
+
## What is Cradova?
|
|
23
28
|
|
|
24
29
|
Cradova is a JavaScript framework for building Single Page Applications and PWAs.
|
|
25
30
|
|
|
26
|
-
It's small, fast and provides state management, routing and
|
|
31
|
+
It's small, fast and provides state management, routing and a rest API utility out of the box.
|
|
32
|
+
|
|
33
|
+
Cradova follows the [VJS specification](https://github.com/fridaycandour/cradova/blob/main/spec.md)
|
|
27
34
|
|
|
28
35
|
## What's the benefit?
|
|
29
|
-
We aim to be fast and simple with and no hidden abstractions whatsoever.
|
|
30
|
-
We don't use visual DOM or any diff algorithms to manage the DOM.
|
|
31
36
|
|
|
32
|
-
Cradova
|
|
37
|
+
Cradova is aimed to be fast and simple with and fewer abstractions and yet easily composable.
|
|
38
|
+
|
|
39
|
+
We don't use visual DOM or diff algorithms to manage the DOM.
|
|
40
|
+
|
|
41
|
+
State management is done more elegantly with the predictive model, manually and easily with all the speed.
|
|
42
|
+
|
|
43
|
+
Cradova has been used on a couple of projects in production and we will update this page to reflect our progress as we keep improving.
|
|
33
44
|
|
|
34
45
|
## Installation
|
|
35
46
|
|
|
@@ -51,36 +62,38 @@ Cradova has been used in production and we will update this README to reflect ou
|
|
|
51
62
|
npm i cradova
|
|
52
63
|
```
|
|
53
64
|
|
|
54
|
-
|
|
55
65
|
## Examples
|
|
66
|
+
|
|
56
67
|
Many aspects of Cradova are not reflected in the following example. More functionality will be entailed in future docs.
|
|
57
68
|
|
|
58
69
|
Here's an example of create a basic component in Cradova:
|
|
59
70
|
|
|
60
71
|
```js
|
|
61
|
-
import _
|
|
72
|
+
import _ from "cradova";
|
|
62
73
|
|
|
63
74
|
function Hello(name) {
|
|
64
75
|
return _("h1", "Hello " + name);
|
|
65
76
|
}
|
|
66
77
|
|
|
67
|
-
//
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
78
|
+
// document fragment empty cradova call _()
|
|
79
|
+
|
|
80
|
+
const html = _(Hello("peter"), Hello("joe"));
|
|
81
|
+
|
|
71
82
|
document.body.append(html);
|
|
72
83
|
```
|
|
73
84
|
|
|
74
85
|
## Using Screen
|
|
86
|
+
|
|
75
87
|
```js
|
|
76
88
|
import _, { Screen, Router } from "cradova";
|
|
77
89
|
|
|
78
90
|
function HelloMessage(name) {
|
|
79
91
|
// an effect run once after screen renders
|
|
80
92
|
this.effect(() => {
|
|
81
|
-
|
|
93
|
+
const name = new Promise((res) => {
|
|
82
94
|
res("friday");
|
|
83
95
|
});
|
|
96
|
+
this.updateState(await name)
|
|
84
97
|
});
|
|
85
98
|
// effects can be used to make api calls needed for the page
|
|
86
99
|
return _("div", "Hello " + name);
|
|
@@ -129,10 +142,21 @@ function counter() {
|
|
|
129
142
|
});
|
|
130
143
|
}
|
|
131
144
|
|
|
132
|
-
function
|
|
145
|
+
function dataCounter() {
|
|
146
|
+
return _("h1| 0", {
|
|
147
|
+
shouldUpdate: true,
|
|
148
|
+
$num: "0", // data-num
|
|
149
|
+
onclick() {
|
|
150
|
+
const num = Number(this.getAttribute("data-num")) + 1;
|
|
151
|
+
this.updateState({ text: num, $num: num });
|
|
152
|
+
},
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function HelloMessage(name = "no name") {
|
|
133
157
|
return _("div.foo#bar", {
|
|
134
158
|
shouldUpdate: true,
|
|
135
|
-
text: "hello " +
|
|
159
|
+
text: "hello " + name,
|
|
136
160
|
onclick() {
|
|
137
161
|
const name = prompt("what are your names");
|
|
138
162
|
this.updateState({ text: "hello " + name });
|
|
@@ -140,13 +164,13 @@ function HelloMessage(name) {
|
|
|
140
164
|
});
|
|
141
165
|
}
|
|
142
166
|
|
|
143
|
-
const nameRef = new Ref(function (
|
|
167
|
+
const nameRef = new Ref(function ( name ) {
|
|
144
168
|
const self = this;
|
|
145
169
|
return _("div.foo#bar", {
|
|
146
170
|
text: "hello" + (name || "no name"),
|
|
147
171
|
onclick() {
|
|
148
172
|
const name = prompt();
|
|
149
|
-
self.updateState(
|
|
173
|
+
self.updateState(name);
|
|
150
174
|
},
|
|
151
175
|
});
|
|
152
176
|
});
|
|
@@ -154,8 +178,9 @@ const nameRef = new Ref(function ({ name }) {
|
|
|
154
178
|
function Home() {
|
|
155
179
|
return _("div.foo#bar",
|
|
156
180
|
counter,
|
|
181
|
+
dataCounter,
|
|
157
182
|
HelloMessage,
|
|
158
|
-
nameRef.render(
|
|
183
|
+
nameRef.render( "no name" )
|
|
159
184
|
);
|
|
160
185
|
}
|
|
161
186
|
|
|
@@ -169,22 +194,27 @@ Router.route("/", home);
|
|
|
169
194
|
```
|
|
170
195
|
|
|
171
196
|
## Documentation
|
|
197
|
+
|
|
172
198
|
We are currently building cradova's documentation and we have only a few hands, if you're interested in helping you can join the community, learn first hand, and support cradova's progress.
|
|
173
199
|
|
|
174
200
|
## Getting Help
|
|
201
|
+
|
|
175
202
|
To get further insights and help on Cradova, visit our new [Telegram Community Chat](https://t.me/cradovaframework).
|
|
176
203
|
|
|
177
204
|
## Contributing
|
|
178
|
-
We are currently working to set up:
|
|
179
205
|
|
|
206
|
+
We are currently working to [set](https://github.com/fridaycandour/cradova/blob/main/contributing.md) up the following:
|
|
207
|
+
|
|
208
|
+
- building cradova CLI (in progress)
|
|
180
209
|
- Cradova Documentation Website
|
|
181
210
|
- UI component libraries for cradova
|
|
182
211
|
- Sample projects
|
|
183
212
|
- maintenance and promotion
|
|
184
|
-
- building cradova CLI
|
|
185
|
-
|
|
186
213
|
|
|
187
214
|
## Sponsor
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
215
|
+
|
|
216
|
+
Your support is appreciated and needed to advance Cradova for more performance and improvements.
|
|
217
|
+
|
|
218
|
+
Sponsorships can be done via [Patreon](https://www.patreon.com/FridayCandour) and [KO-FI](https://www.ko-fi.com/fridaycandour).
|
|
219
|
+
|
|
220
|
+
Both monthly-recurring sponsorships and one-time donations are accepted.
|
package/dist/index.d.ts
CHANGED
|
@@ -35,9 +35,7 @@ declare module "cradova" {
|
|
|
35
35
|
updateState(data: unknown): void;
|
|
36
36
|
};
|
|
37
37
|
|
|
38
|
-
type
|
|
39
|
-
|
|
40
|
-
type RefType = {
|
|
38
|
+
export type RefType<D> = {
|
|
41
39
|
/**
|
|
42
40
|
* Cradova Ref
|
|
43
41
|
* ---
|
|
@@ -45,7 +43,7 @@ declare module "cradova" {
|
|
|
45
43
|
* @param data
|
|
46
44
|
* @returns HTMLElement
|
|
47
45
|
*/
|
|
48
|
-
render(data?:
|
|
46
|
+
render(data?: D): () => any;
|
|
49
47
|
/**
|
|
50
48
|
* Cradova Ref
|
|
51
49
|
* ---
|
|
@@ -61,7 +59,7 @@ declare module "cradova" {
|
|
|
61
59
|
* @param data
|
|
62
60
|
* @returns void
|
|
63
61
|
*/
|
|
64
|
-
updateState(data:
|
|
62
|
+
updateState(data: D, stash?: boolean): void;
|
|
65
63
|
/**
|
|
66
64
|
* Cradova Ref
|
|
67
65
|
* ---
|
|
@@ -77,7 +75,15 @@ declare module "cradova" {
|
|
|
77
75
|
*
|
|
78
76
|
*/
|
|
79
77
|
effect(fn: (data: unknown) => Promise<void> | void): void;
|
|
78
|
+
/**
|
|
79
|
+
* Cradova Ref
|
|
80
|
+
* ---
|
|
81
|
+
* returns last set stashed Ref data
|
|
82
|
+
*
|
|
83
|
+
*/
|
|
84
|
+
stash: D;
|
|
80
85
|
};
|
|
86
|
+
|
|
81
87
|
/**
|
|
82
88
|
* Cradova Router
|
|
83
89
|
* ---
|
|
@@ -235,7 +241,7 @@ declare module "cradova" {
|
|
|
235
241
|
* - update a cradova Ref automatically
|
|
236
242
|
* @constructor initial: any, props: {useHistory, persist}
|
|
237
243
|
*/
|
|
238
|
-
export class createSignal {
|
|
244
|
+
export class createSignal<Type> {
|
|
239
245
|
private callback;
|
|
240
246
|
private persistName;
|
|
241
247
|
private actions;
|
|
@@ -246,7 +252,7 @@ declare module "cradova" {
|
|
|
246
252
|
private path;
|
|
247
253
|
value: any;
|
|
248
254
|
constructor(
|
|
249
|
-
initial:
|
|
255
|
+
initial: Type,
|
|
250
256
|
props?: {
|
|
251
257
|
useHistory?: boolean;
|
|
252
258
|
persistName?: string | undefined;
|
|
@@ -259,46 +265,21 @@ declare module "cradova" {
|
|
|
259
265
|
* @param value - signal value
|
|
260
266
|
* @returns void
|
|
261
267
|
*/
|
|
262
|
-
set(value:
|
|
268
|
+
set(value: Type, shouldRefRender?: boolean): void;
|
|
263
269
|
/**
|
|
264
270
|
* Cradova Signal
|
|
265
271
|
* ----
|
|
266
272
|
* set a key value if it's an object
|
|
267
273
|
* @param name - name of the key
|
|
268
274
|
* @param value - value of the key
|
|
275
|
+
* @param shouldRefRender? boolean
|
|
269
276
|
* @returns void
|
|
277
|
+
*
|
|
278
|
+
*
|
|
279
|
+
* .
|
|
280
|
+
*
|
|
270
281
|
*/
|
|
271
|
-
setKey(name: string, value:
|
|
272
|
-
/**
|
|
273
|
-
* Cradova Signal
|
|
274
|
-
* ----
|
|
275
|
-
* set a prop value inside an object prop of the store
|
|
276
|
-
* @param key - a prop of the store - object value
|
|
277
|
-
* @param name - prop of the key object
|
|
278
|
-
* @param value - value of the name
|
|
279
|
-
* @returns void
|
|
280
|
-
*/
|
|
281
|
-
setPath(
|
|
282
|
-
key: string,
|
|
283
|
-
name: string,
|
|
284
|
-
value: any,
|
|
285
|
-
shouldRefRender?: boolean
|
|
286
|
-
): void;
|
|
287
|
-
/**
|
|
288
|
-
* Cradova Signal
|
|
289
|
-
* ----
|
|
290
|
-
* set a prop value inside an array prop of the store
|
|
291
|
-
* @param key - a prop of the store - object value
|
|
292
|
-
* @param index - index of the key object
|
|
293
|
-
* @param value - value of the index
|
|
294
|
-
* @returns void
|
|
295
|
-
*/
|
|
296
|
-
setIndex(
|
|
297
|
-
key: string,
|
|
298
|
-
index: number,
|
|
299
|
-
value: any,
|
|
300
|
-
shouldRefRender?: boolean
|
|
301
|
-
): void;
|
|
282
|
+
setKey(name: string, value: unknown, shouldRefRender?: boolean): void;
|
|
302
283
|
/**
|
|
303
284
|
* Cradova Signal
|
|
304
285
|
* ----
|
|
@@ -307,8 +288,8 @@ declare module "cradova" {
|
|
|
307
288
|
* @param action function to execute
|
|
308
289
|
*/
|
|
309
290
|
createAction(
|
|
310
|
-
name: string | Record<string, (self?:
|
|
311
|
-
action?: (self?:
|
|
291
|
+
name: string | Record<string, (self?: this, data?: Type) => void>,
|
|
292
|
+
action?: (self?: this, data?: any) => void
|
|
312
293
|
): void;
|
|
313
294
|
/**
|
|
314
295
|
* Cradova Signal
|
|
@@ -317,7 +298,7 @@ declare module "cradova" {
|
|
|
317
298
|
* @param name - string name of the action
|
|
318
299
|
* @param data - data for the action
|
|
319
300
|
*/
|
|
320
|
-
fireAction(name: string, data?:
|
|
301
|
+
fireAction(name: string, data?: Type): void;
|
|
321
302
|
/**
|
|
322
303
|
* Cradova Signal
|
|
323
304
|
* ----
|
|
@@ -347,7 +328,7 @@ declare module "cradova" {
|
|
|
347
328
|
* set a update listener on value changes
|
|
348
329
|
* @param callback
|
|
349
330
|
*/
|
|
350
|
-
listen(callback: (
|
|
331
|
+
listen(callback: (data: Type) => void): void;
|
|
351
332
|
/**
|
|
352
333
|
* Cradova Signal
|
|
353
334
|
* ----
|
|
@@ -367,10 +348,10 @@ declare module "cradova" {
|
|
|
367
348
|
* @constructor initial: any, Ref: any
|
|
368
349
|
*/
|
|
369
350
|
|
|
370
|
-
export class
|
|
351
|
+
export class $<Type> {
|
|
371
352
|
private ref;
|
|
372
353
|
value: any;
|
|
373
|
-
constructor(initial:
|
|
354
|
+
constructor(initial: Type);
|
|
374
355
|
/**
|
|
375
356
|
* Cradova simpleStore
|
|
376
357
|
* ----
|
|
@@ -378,7 +359,7 @@ declare module "cradova" {
|
|
|
378
359
|
* @param value - simpleStore value
|
|
379
360
|
* @returns void
|
|
380
361
|
*/
|
|
381
|
-
set(value:
|
|
362
|
+
set(value: Type, shouldRefRender?: boolean): void;
|
|
382
363
|
/**
|
|
383
364
|
* Cradova simpleStore
|
|
384
365
|
* ----
|
|
@@ -387,7 +368,7 @@ declare module "cradova" {
|
|
|
387
368
|
* @param value - value of the key
|
|
388
369
|
* @returns void
|
|
389
370
|
*/
|
|
390
|
-
setKey(name: string, value:
|
|
371
|
+
setKey(name: string, value: unknown, shouldRefRender?: boolean): void;
|
|
391
372
|
/**
|
|
392
373
|
* Cradova simpleStore
|
|
393
374
|
* ---
|
|
@@ -414,9 +395,9 @@ declare module "cradova" {
|
|
|
414
395
|
url: string | URL,
|
|
415
396
|
opts?:
|
|
416
397
|
| {
|
|
417
|
-
method?:
|
|
398
|
+
method?: "GET" | "POST";
|
|
418
399
|
data?: Record<string, any>;
|
|
419
|
-
header?: Record<string, any>;
|
|
400
|
+
header?: { "content-type": string } & Record<string, any>;
|
|
420
401
|
callbacks?: Record<string, (arg: any) => void>;
|
|
421
402
|
}
|
|
422
403
|
| any
|
|
@@ -480,8 +461,8 @@ css(".btn:hover",
|
|
|
480
461
|
* create dynamic components
|
|
481
462
|
*
|
|
482
463
|
*/
|
|
483
|
-
export class Ref {
|
|
484
|
-
constructor(component: (
|
|
464
|
+
export class Ref<D> {
|
|
465
|
+
constructor(component: (data: D) => any);
|
|
485
466
|
/**
|
|
486
467
|
* Cradova Ref
|
|
487
468
|
* ---
|
|
@@ -489,7 +470,7 @@ css(".btn:hover",
|
|
|
489
470
|
* @param data
|
|
490
471
|
* @returns HTMLElement
|
|
491
472
|
*/
|
|
492
|
-
render(data?:
|
|
473
|
+
render(data?: D, stash?: boolean): () => any;
|
|
493
474
|
/**
|
|
494
475
|
* Cradova Ref
|
|
495
476
|
* ---
|
|
@@ -505,7 +486,7 @@ css(".btn:hover",
|
|
|
505
486
|
* @param data
|
|
506
487
|
* @returns void
|
|
507
488
|
*/
|
|
508
|
-
updateState(data:
|
|
489
|
+
updateState(data: D, stashed?: boolean): void;
|
|
509
490
|
/**
|
|
510
491
|
* Cradova Ref
|
|
511
492
|
* ---
|
|
@@ -521,6 +502,13 @@ css(".btn:hover",
|
|
|
521
502
|
*
|
|
522
503
|
*/
|
|
523
504
|
effect(fn: (data: unknown) => Promise<void> | void): void;
|
|
505
|
+
/**
|
|
506
|
+
* Cradova Ref
|
|
507
|
+
* ---
|
|
508
|
+
* returns last set stashed Ref data
|
|
509
|
+
*
|
|
510
|
+
*/
|
|
511
|
+
stash: D;
|
|
524
512
|
}
|
|
525
513
|
|
|
526
514
|
/**
|