@katabatic/runtime 1.1.1 → 1.1.3

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": "@katabatic/runtime",
3
3
  "license": "MIT",
4
- "version": "1.1.1",
4
+ "version": "1.1.3",
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.0"
18
+ "@katabatic/signals": "^1.0.4"
19
19
  },
20
20
  "devDependencies": {
21
21
  "@vitest/browser": "^4.1.0",
package/src/client.js CHANGED
@@ -3,7 +3,7 @@ import { Animate } from './animate.js'
3
3
 
4
4
  export class Client extends Set {
5
5
  effect(fn) {
6
- const effect = new Effect(fn, { orphaned: true, async: true }).run()
6
+ const effect = new Effect(fn, { orphaned: true }).run()
7
7
  this.add(effect)
8
8
  return effect
9
9
  }
package/src/eachBlock.js CHANGED
@@ -1,5 +1,4 @@
1
- import { Signal, SignalEvent, Effect, track } from '@katabatic/signals'
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 {
@@ -94,7 +93,7 @@ export class EachBlock extends Map {
94
93
  index++
95
94
  }
96
95
  },
97
- { orphaned: true, async: true }
96
+ { orphaned: true }
98
97
  ).run()
99
98
 
100
99
  return this
@@ -133,24 +132,22 @@ class Block extends AnimatedClient {
133
132
  super()
134
133
  this.key = key
135
134
  this.value = value
136
- this.signal = new Signal(undefined, this)
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
142
  const hasChange = this.value !== nextValue
146
143
  this.value = nextValue
147
144
  if (hasChange) {
148
- this.signal.dispatchEvent(new SignalEvent('change'))
145
+ this.signal.dispatchEvent(new SignalEvent('changed'))
149
146
  }
150
147
  }
151
148
 
152
149
  getValue = () => {
153
- track?.(new Tracker(this.signal))
150
+ this.signal.trackEvent('changed')
154
151
  return this.value
155
152
  }
156
153
 
@@ -181,14 +178,14 @@ class Block extends AnimatedClient {
181
178
  }
182
179
 
183
180
  get nextNode() {
184
- return this.anchor?.nextSibling ?? this.parentAnchor.firstChild
181
+ return this.anchor?.nextSibling
185
182
  }
186
183
  }
187
184
 
188
185
  function createHeadBlock(anchor) {
189
186
  const block = new Block()
190
- block.anchor = anchor.previousSibling
191
- block.parentAnchor = block.anchor ? undefined : anchor.parentNode
187
+ block.anchor = document.createComment('')
188
+ anchor.parentNode.insertBefore(block.anchor, anchor)
192
189
  return block
193
190
  }
194
191
 
package/src/ifBlock.js CHANGED
@@ -46,6 +46,7 @@ export class IfBlock {
46
46
  init() {
47
47
  this.#effect = new Effect(
48
48
  () => {
49
+ console.log
49
50
  if (this.getCondition()) {
50
51
  this.#altBlock?.out(() => this.#removeBlock(this.#altBlock))
51
52
  this.#condBlock ??= this.#insertBlock(new Block(), this.concequent)
@@ -58,7 +59,7 @@ export class IfBlock {
58
59
  }
59
60
  }
60
61
  },
61
- { orphaned: true, async: true }
62
+ { orphaned: true }
62
63
  ).run()
63
64
 
64
65
  return this
@@ -87,15 +88,13 @@ export function ifBlock(anchor, getCondition, concequent, alternate) {
87
88
 
88
89
  class Block extends AnimatedClient {
89
90
  get nextNode() {
90
- return this.anchor?.nextSibling ?? this.parentAnchor.firstChild
91
+ return this.anchor?.nextSibling
91
92
  }
92
93
  }
93
94
 
94
95
  function createHeadBlock(anchor) {
95
96
  const block = new Block()
96
-
97
97
  block.anchor = document.createComment('')
98
98
  anchor.parentNode.insertBefore(block.anchor, anchor)
99
-
100
99
  return block
101
100
  }
package/src/index.js CHANGED
@@ -20,6 +20,7 @@ export function $$(customElement) {
20
20
  }
21
21
 
22
22
  const client = new Client()
23
+ const signal = new Signal(customElement)
23
24
 
24
25
  client.boundary = function (fn) {
25
26
  const boundary = new Boundary(fn, { orphaned: true }).init()
@@ -68,22 +69,18 @@ export function $$(customElement) {
68
69
  }
69
70
 
70
71
  client.instrument = function (property) {
71
- this.signal ??= new Signal(undefined, customElement)
72
-
73
72
  if (!Object.getOwnPropertyDescriptor(customElement, property)?.get) {
74
73
  let value = customElement[property]
74
+
75
75
  Object.defineProperty(customElement, property, {
76
76
  get: () => {
77
- track?.(new PropertyTracker(this.signal, property))
77
+ track(() => new PropertyTracker(signal, property))
78
78
  return value
79
79
  },
80
80
  set: (nextValue) => {
81
- const hasChange = value !== nextValue
82
- value = nextValue
83
-
84
- if (hasChange) {
85
- this.signal.dispatchEvent(new SignalEvent('set', { property }))
86
- this.signal.dispatchEvent(new SignalEvent('change'))
81
+ if (nextValue !== value) {
82
+ value = nextValue
83
+ signal.dispatchEvent(new SignalEvent('propertyChanged', { property }))
87
84
  }
88
85
  }
89
86
  })
@@ -91,14 +88,12 @@ export function $$(customElement) {
91
88
  }
92
89
 
93
90
  client.trackAttribute = function (name) {
94
- this.signal ??= new Signal(undefined, customElement)
95
- track?.(new AttributeTracker(this.signal, name))
91
+ track(() => new AttributeTracker(signal, name))
96
92
  }
97
93
 
98
94
  client.attributeChanged = function (name, value, nextValue) {
99
95
  if (value !== nextValue) {
100
- this.signal ??= new Signal(undefined, customElement)
101
- this.signal.dispatchEvent(new SignalEvent('attributeChanged', { name }))
96
+ signal.dispatchEvent(new SignalEvent('attributeChanged', { name }))
102
97
  }
103
98
  }
104
99