@katabatic/runtime 1.1.2 → 1.1.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/package.json +2 -2
- package/src/eachBlock.js +10 -14
- package/src/ifBlock.js +1 -3
- package/src/index.js +29 -13
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@katabatic/runtime",
|
|
3
3
|
"license": "MIT",
|
|
4
|
-
"version": "1.1.
|
|
4
|
+
"version": "1.1.4",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
}
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@katabatic/signals": "^1.0.
|
|
18
|
+
"@katabatic/signals": "^1.0.4"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"@vitest/browser": "^4.1.0",
|
package/src/eachBlock.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { Signal, SignalEvent, Effect
|
|
2
|
-
import { Tracker } from '@katabatic/signals/tracker'
|
|
1
|
+
import { Signal, SignalEvent, Effect } from '@katabatic/signals'
|
|
3
2
|
import { AnimatedClient } from './client.js'
|
|
4
3
|
|
|
5
4
|
export class EachBlock extends Map {
|
|
@@ -68,7 +67,7 @@ export class EachBlock extends Map {
|
|
|
68
67
|
init() {
|
|
69
68
|
this.#effect = new Effect(
|
|
70
69
|
() => {
|
|
71
|
-
const iterable = this.getIterable()
|
|
70
|
+
const iterable = [...this.getIterable() ?? []]
|
|
72
71
|
|
|
73
72
|
for (const block of this.#getRemovedBlocks(iterable)) {
|
|
74
73
|
this.#removeBlock(block)
|
|
@@ -133,24 +132,21 @@ class Block extends AnimatedClient {
|
|
|
133
132
|
super()
|
|
134
133
|
this.key = key
|
|
135
134
|
this.value = value
|
|
136
|
-
this.signal = new Signal(
|
|
135
|
+
this.signal = new Signal(this)
|
|
137
136
|
}
|
|
138
137
|
|
|
139
138
|
/** @type {Node} */
|
|
140
139
|
anchor
|
|
141
|
-
/** @type {Node} */
|
|
142
|
-
parentAnchor
|
|
143
140
|
|
|
144
141
|
setValue(nextValue) {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
this.signal.dispatchEvent(new SignalEvent('change'))
|
|
142
|
+
if (this.value !== nextValue) {
|
|
143
|
+
this.value = nextValue
|
|
144
|
+
this.signal.dispatchEvent(new SignalEvent('changed'))
|
|
149
145
|
}
|
|
150
146
|
}
|
|
151
147
|
|
|
152
148
|
getValue = () => {
|
|
153
|
-
|
|
149
|
+
this.signal.trackEvent('changed')
|
|
154
150
|
return this.value
|
|
155
151
|
}
|
|
156
152
|
|
|
@@ -181,14 +177,14 @@ class Block extends AnimatedClient {
|
|
|
181
177
|
}
|
|
182
178
|
|
|
183
179
|
get nextNode() {
|
|
184
|
-
return this.anchor?.nextSibling
|
|
180
|
+
return this.anchor?.nextSibling
|
|
185
181
|
}
|
|
186
182
|
}
|
|
187
183
|
|
|
188
184
|
function createHeadBlock(anchor) {
|
|
189
185
|
const block = new Block()
|
|
190
|
-
block.anchor =
|
|
191
|
-
|
|
186
|
+
block.anchor = document.createComment('')
|
|
187
|
+
anchor.parentNode.insertBefore(block.anchor, anchor)
|
|
192
188
|
return block
|
|
193
189
|
}
|
|
194
190
|
|
package/src/ifBlock.js
CHANGED
|
@@ -88,15 +88,13 @@ export function ifBlock(anchor, getCondition, concequent, alternate) {
|
|
|
88
88
|
|
|
89
89
|
class Block extends AnimatedClient {
|
|
90
90
|
get nextNode() {
|
|
91
|
-
return this.anchor?.nextSibling
|
|
91
|
+
return this.anchor?.nextSibling
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
function createHeadBlock(anchor) {
|
|
96
96
|
const block = new Block()
|
|
97
|
-
|
|
98
97
|
block.anchor = document.createComment('')
|
|
99
98
|
anchor.parentNode.insertBefore(block.anchor, anchor)
|
|
100
|
-
|
|
101
99
|
return block
|
|
102
100
|
}
|
package/src/index.js
CHANGED
|
@@ -20,6 +20,8 @@ export function $$(customElement) {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
const client = new Client()
|
|
23
|
+
const signal = new Signal(customElement)
|
|
24
|
+
const bindings = new WeakMap()
|
|
23
25
|
|
|
24
26
|
client.boundary = function (fn) {
|
|
25
27
|
const boundary = new Boundary(fn, { orphaned: true }).init()
|
|
@@ -68,22 +70,18 @@ export function $$(customElement) {
|
|
|
68
70
|
}
|
|
69
71
|
|
|
70
72
|
client.instrument = function (property) {
|
|
71
|
-
this.signal ??= new Signal(undefined, customElement)
|
|
72
|
-
|
|
73
73
|
if (!Object.getOwnPropertyDescriptor(customElement, property)?.get) {
|
|
74
74
|
let value = customElement[property]
|
|
75
|
+
|
|
75
76
|
Object.defineProperty(customElement, property, {
|
|
76
77
|
get: () => {
|
|
77
|
-
track
|
|
78
|
+
track(() => new PropertyTracker(signal, property))
|
|
78
79
|
return value
|
|
79
80
|
},
|
|
80
81
|
set: (nextValue) => {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
if (hasChange) {
|
|
85
|
-
this.signal.dispatchEvent(new SignalEvent('set', { property }))
|
|
86
|
-
this.signal.dispatchEvent(new SignalEvent('change'))
|
|
82
|
+
if (nextValue !== value) {
|
|
83
|
+
value = nextValue
|
|
84
|
+
signal.dispatchEvent(new SignalEvent('propertyChanged', { property }))
|
|
87
85
|
}
|
|
88
86
|
}
|
|
89
87
|
})
|
|
@@ -91,15 +89,33 @@ export function $$(customElement) {
|
|
|
91
89
|
}
|
|
92
90
|
|
|
93
91
|
client.trackAttribute = function (name) {
|
|
94
|
-
|
|
95
|
-
track?.(new AttributeTracker(this.signal, name))
|
|
92
|
+
track(() => new AttributeTracker(signal, name))
|
|
96
93
|
}
|
|
97
94
|
|
|
98
95
|
client.attributeChanged = function (name, value, nextValue) {
|
|
99
96
|
if (value !== nextValue) {
|
|
100
|
-
|
|
101
|
-
|
|
97
|
+
signal.dispatchEvent(new SignalEvent('attributeChanged', { name }))
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
client.bind = function(element, fn, _client) {
|
|
102
|
+
function opts(value) {
|
|
103
|
+
return {...value, getBinding: client.getBinding}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const binding = fn(opts)
|
|
107
|
+
bindings.set(element, binding)
|
|
108
|
+
_client.add(binding)
|
|
109
|
+
return binding
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
client.getBinding = function (element) {
|
|
113
|
+
let binding = bindings.get(element)
|
|
114
|
+
if (!binding) {
|
|
115
|
+
binding = {}
|
|
116
|
+
bindings.set(element, binding)
|
|
102
117
|
}
|
|
118
|
+
return binding
|
|
103
119
|
}
|
|
104
120
|
|
|
105
121
|
return client
|