sprae 11.0.0 → 11.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "sprae",
3
3
  "description": "DOM microhydration.",
4
- "version": "11.0.0",
4
+ "version": "11.0.2",
5
5
  "main": "./sprae.js",
6
6
  "module": "./sprae.js",
7
7
  "unpkg": "dist/sprae.umd.min.js",
package/readme.md CHANGED
@@ -171,13 +171,16 @@ Run effect, not changing any attribute.
171
171
  Get reference to element (instead of `this`).
172
172
 
173
173
  ```html
174
- <!-- initialize el (oninit) -->
175
- <textarea :ref="el => autoResize(el)" placeholder="Enter text..."></textarea>
174
+ <!-- initialize element -->
175
+ <textarea :ref="el => (/* onmount */, () => (/* onunmount */))" placeholder="Enter text..."></textarea>
176
176
 
177
177
  <!-- expose element in (sub)state -->
178
178
  <li :each="item in items" :with="{li:null}" :ref="el => li = el">
179
179
  <input :onfocus..onblur="e => (li.classList.add('editing'), e => li.classList.remove('editing'))"/>
180
180
  </li>
181
+
182
+ <!-- set innerHTML -->
183
+ <div :ref="el => el.innerHTML = '...'"></div>
181
184
  ```
182
185
 
183
186
  #### `:on<event>="handler"`, `:on<in>..on<out>="handler"`
@@ -263,7 +266,7 @@ Trigger when element is connected / disconnected from DOM.
263
266
  ## Signals
264
267
 
265
268
  Sprae uses _preact-flavored signals_ for reactivity and can take _signal_ values as inputs.<br/>
266
- Signals can be switched to any preact/compatible implementation:
269
+ Signals can be switched to an alternative preact/compatible implementation:
267
270
 
268
271
  ```js
269
272
  import sprae from 'sprae';
@@ -348,13 +351,13 @@ sprae.use({ compile })
348
351
 
349
352
  * To prevent [FOUC](https://en.wikipedia.org/wiki/Flash_of_unstyled_content) add `<style>[:each],[:if],[:else] {visibility: hidden}</style>`.
350
353
  * 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>`.
351
- * Mind invalid self-closing tags, eg. `<a :text="item" />` will cause an error. Main valid self-closing tags are `li`, `p`, `dt`, `dd`, `option`, `tr`, `td`, `th`.
354
+ * Invalid self-closing tags like `<a :text="item" />` will cause error. Valid self-closing tags are: `li`, `p`, `dt`, `dd`, `option`, `tr`, `td`, `th`.
352
355
  * Properties prefixed with `_` are untracked: `let state = sprae(el, {_x:2}); state._x++; // no effect`.
353
356
  * To destroy state and detach sprae handlers, call `element[Symbol.dispose]()`.
354
357
  * State getters/setters work as computed effects, eg. `sprae(el, { x:1, get x2(){ return this.x * 2} })`.
355
- * `this` is not used, to get access to current element use `<input :ref="el" :text="el.value"/>`.
356
- * `event` is not used, `:on*` attributes expect a function with event object as first argument `:onevt="event => handle()"`, see [#46](https://github.com/dy/sprae/issues/46).
357
- * `key` is not used, `:each` uses direct list mapping instead of dom diffing.
358
+ * `this` is not used, to get access to current element use `<input :ref="el => (...)" />`.
359
+ * `event` is not used, `:on*` attributes expect a function with event argument `:onevt="event => handle()"`, see [#46](https://github.com/dy/sprae/issues/46).
360
+ * `key` is not used, `:each` uses direct list mapping instead of DOM diffing.
358
361
  * `await` is not supported in attributes, it’s a strong indicator you need to put these methods into state.
359
362
 
360
363
  ## Justification
package/store.js CHANGED
@@ -21,7 +21,7 @@ export default function store(values, parent) {
21
21
 
22
22
  // proxy conducts prop access to signals
23
23
  const state = new Proxy(signals, {
24
- get: (_, key) => key === _change ? _len : key === _signals ? signals : (signals[key]?.valueOf()),
24
+ get: (_, key) => key === _change ? _len : key === _signals ? signals : signals[key]?.valueOf(),
25
25
  set: (_, key, v, s) => (s = signals[key], set(signals, key, v), s ?? (++_len.value), 1), // bump length for new signal
26
26
  deleteProperty: (_, key) => (signals[key] && (del(signals, key), _len.value--), 1),
27
27
  ownKeys() {
@@ -72,7 +72,6 @@ export function list(values) {
72
72
  // covers Symbol.isConcatSpreadable etc.
73
73
  if (typeof key === 'symbol') return key === _change ? _len : key === _signals ? signals : signals[key]
74
74
 
75
- // console.log('get', key)
76
75
  // if .length is read within .push/etc - peek signal to avoid recursive subscription
77
76
  if (key === 'length') return mut[lastProp] ? _len.peek() : _len.value;
78
77
 
@@ -85,7 +84,6 @@ export function list(values) {
85
84
  },
86
85
 
87
86
  set(_, key, v) {
88
- // console.log('set', key, v)
89
87
  // .length
90
88
  if (key === 'length') {
91
89
  // force cleaning up tail