sprae 10.9.2 → 10.9.4
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/directive/style.js +4 -5
- package/dist/sprae.js +10 -6
- package/dist/sprae.js.map +2 -2
- package/dist/sprae.min.js +3 -3
- package/dist/sprae.min.js.map +4 -4
- package/dist/sprae.umd.js +625 -56
- package/dist/sprae.umd.js.map +4 -4
- package/dist/sprae.umd.min.js +3 -33
- package/dist/sprae.umd.min.js.map +4 -4
- package/package.json +1 -2
- package/readme.md +13 -26
- package/sprae.js +6 -0
package/readme.md
CHANGED
|
@@ -17,6 +17,7 @@ A light alternative to alpine, petite-vue etc.
|
|
|
17
17
|
import sprae from 'sprae'
|
|
18
18
|
|
|
19
19
|
// init
|
|
20
|
+
const container = document.querySelector('#container');
|
|
20
21
|
const state = sprae(container, { user: { name: 'Kitty' } })
|
|
21
22
|
|
|
22
23
|
// update
|
|
@@ -26,7 +27,7 @@ A light alternative to alpine, petite-vue etc.
|
|
|
26
27
|
|
|
27
28
|
Sprae evaluates `:`-directives and evaporates them, returning reactive state for updates.
|
|
28
29
|
|
|
29
|
-
###
|
|
30
|
+
### Standalone
|
|
30
31
|
|
|
31
32
|
```html
|
|
32
33
|
<script src="https://cdn.jsdelivr.net/npm/sprae/dist/sprae.umd.js" init></script>
|
|
@@ -35,14 +36,8 @@ Sprae evaluates `:`-directives and evaporates them, returning reactive state for
|
|
|
35
36
|
</script>
|
|
36
37
|
```
|
|
37
38
|
|
|
38
|
-
`init` attribute autoinits sprae on document
|
|
39
|
-
|
|
40
|
-
### As CJS etc.
|
|
41
|
-
|
|
42
|
-
```js
|
|
43
|
-
const sprae = require('sprae/dist/sprae.umd.js');
|
|
44
|
-
sprae(el);
|
|
45
|
-
```
|
|
39
|
+
`init` attribute autoinits sprae on document.<br>
|
|
40
|
+
`sprae.umd.js` can be also used as commonjs.
|
|
46
41
|
|
|
47
42
|
|
|
48
43
|
## Directives
|
|
@@ -60,12 +55,12 @@ Control flow of elements.
|
|
|
60
55
|
<template :if="foo">foo <span>bar</span> baz</template>
|
|
61
56
|
```
|
|
62
57
|
|
|
63
|
-
|
|
64
58
|
#### `:each="item, index? in items"`
|
|
65
59
|
|
|
66
60
|
Multiply element.
|
|
67
61
|
|
|
68
62
|
```html
|
|
63
|
+
<!-- :text order matters -->
|
|
69
64
|
<ul><li :each="item in items" :text="item"/></ul>
|
|
70
65
|
|
|
71
66
|
<!-- cases -->
|
|
@@ -109,13 +104,13 @@ Set style value.
|
|
|
109
104
|
|
|
110
105
|
```html
|
|
111
106
|
<!-- extends style -->
|
|
112
|
-
<div style="foo: bar" :style="'baz: qux'">
|
|
107
|
+
<div style="foo: bar" :style="'baz-baz: qux'">
|
|
113
108
|
|
|
114
109
|
<!-- object -->
|
|
115
|
-
<div :style="{
|
|
110
|
+
<div :style="{bazBaz: 'qux'}"></div>
|
|
116
111
|
|
|
117
112
|
<!-- CSS variable -->
|
|
118
|
-
<div :style="{'--baz': qux}"></div>
|
|
113
|
+
<div :style="{'--baz-baz': qux}"></div>
|
|
119
114
|
```
|
|
120
115
|
|
|
121
116
|
#### `:value="value"`
|
|
@@ -287,7 +282,7 @@ Trigger when element is connected / disconnected from DOM.
|
|
|
287
282
|
|
|
288
283
|
## Signals
|
|
289
284
|
|
|
290
|
-
Sprae uses signals for reactivity and can take signal values as inputs
|
|
285
|
+
Sprae uses signals for reactivity and can take signal values as inputs.<br/>
|
|
291
286
|
Signals provider can be switched to any preact-flavored implementation:
|
|
292
287
|
|
|
293
288
|
```js
|
|
@@ -314,15 +309,6 @@ Provider | Size | Feature
|
|
|
314
309
|
[`@preact/signals-core`](https://ghub.io/@preact/signals-core) | 1.47kb | Best performance, good for any states, industry standard.
|
|
315
310
|
[`signal-polyfill`](https://github.com/proposal-signals/signal-polyfill) | 2.5kb | Proposal signals. Use via [adapter](https://gist.github.com/dy/bbac687464ccf5322ab0e2fd0680dc4d).
|
|
316
311
|
|
|
317
|
-
## Untracked
|
|
318
|
-
|
|
319
|
-
Properties prefixed with `_` indicate untracked value:
|
|
320
|
-
|
|
321
|
-
```js
|
|
322
|
-
let state = sprae(el, {x:1, _y:2})
|
|
323
|
-
state.x++ // updates template
|
|
324
|
-
state._y++ // no side-effect
|
|
325
|
-
```
|
|
326
312
|
|
|
327
313
|
## Evaluator
|
|
328
314
|
|
|
@@ -381,11 +367,12 @@ sprae.use({ compile })
|
|
|
381
367
|
|
|
382
368
|
## Hints
|
|
383
369
|
|
|
384
|
-
* To prevent [FOUC](https://en.wikipedia.org/wiki/Flash_of_unstyled_content) add `<style>[:each],[:if],[:else] {visibility: hidden}</style
|
|
385
|
-
* Attributes order matters, eg. `<li :each="el in els" :text="el.name"></li>` is not the same as `<li :text="el.name" :each="el in els"></li
|
|
370
|
+
* To prevent [FOUC](https://en.wikipedia.org/wiki/Flash_of_unstyled_content) add `<style>[:each],[:if],[:else] {visibility: hidden}</style>`.
|
|
371
|
+
* Attributes order matters, eg. `<li :each="el in els" :text="el.name"></li>` is not the same as `<li :text="el.name" :each="el in els"></li>`.
|
|
372
|
+
* Properties prefixed with `_` are untracked: `let state = sprae(el, {_x:2}); state._x++; // no effect`.
|
|
386
373
|
* To destroy state and detach sprae handlers, call `element[Symbol.dispose]()`.
|
|
387
374
|
* State getters/setters work as computed effects, eg. `sprae(el, { x:1, get x2(){ return this.x * 2} })`.
|
|
388
|
-
* `this` keyword is not used, to get access to current element use `<input :ref="el" :text="el.value"
|
|
375
|
+
* `this` keyword is not used, to get access to current element use `<input :ref="el" :text="el.value"/>`.
|
|
389
376
|
* Async/await is not supported in attributes, it's a strong indicator you need to put these methods into state.
|
|
390
377
|
|
|
391
378
|
## Justification
|
package/sprae.js
CHANGED
|
@@ -22,3 +22,9 @@ sprae.use(signals)
|
|
|
22
22
|
sprae.use({ compile: expr => sprae.constructor(`with (arguments[0]) { return ${expr} };`) })
|
|
23
23
|
|
|
24
24
|
export default sprae
|
|
25
|
+
|
|
26
|
+
// standalone run
|
|
27
|
+
if (document?.currentScript) {
|
|
28
|
+
window.sprae = sprae
|
|
29
|
+
if (document.currentScript.hasAttribute('init')) sprae(document.documentElement);
|
|
30
|
+
}
|