dazscript-framework 0.3.2 → 1.0.1
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 +327 -267
- package/package.json +7 -4
- package/src/Setup.dsa.ts +37 -9
- package/src/dialog/builders/list-view-builder.ts +5 -0
- package/src/examples/01-hello-world.dsa.ts +8 -0
- package/src/examples/02-persistence-dialog.dsa.ts +21 -0
- package/src/examples/02-persistence-dialog.ts +68 -0
- package/src/examples/03-simple-dialog.dsa.ts +23 -0
- package/src/examples/03-simple-dialog.ts +47 -0
- package/src/examples/04-settings-dialog.dsa.ts +29 -0
- package/src/examples/04-settings-dialog.ts +83 -0
- package/src/examples/05-list-dialog.dsa.ts +53 -0
- package/src/examples/05-list-dialog.ts +88 -0
- package/src/examples/06-showcase-dialog.dsa.ts +87 -0
- package/src/examples/06-showcase-dialog.ts +518 -0
- package/src/helpers/custom-action-helper.ts +2 -1
- package/src/helpers/custom-action-installer-helper.ts +39 -10
- package/src/lib/observable.test.ts +416 -0
- package/src/lib/observable.ts +24 -18
- package/src/lib/tree-node.test.ts +21 -0
- package/tsconfig.json +28 -112
- package/webpack.config.js +1 -0
- package/src/samples/hello-world.dsa.ts +0 -8
- package/src/samples/sample-dialog.dsa.ts +0 -47
- package/src/samples/sample-dialog.ts +0 -49
- /package/src/{samples → examples}/config.ts +0 -0
|
@@ -0,0 +1,416 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest'
|
|
2
|
+
import { BooleanObservable, Observable } from './observable'
|
|
3
|
+
|
|
4
|
+
// ─── Observable ───────────────────────────────────────────────────────────────
|
|
5
|
+
|
|
6
|
+
describe('Observable — constructor', () => {
|
|
7
|
+
it('initializes with undefined when no value is provided', () => {
|
|
8
|
+
const obs = new Observable<string>()
|
|
9
|
+
expect(obs.value).toBeUndefined()
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
it('initializes with the provided value', () => {
|
|
13
|
+
const obs = new Observable(42)
|
|
14
|
+
expect(obs.value).toBe(42)
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
it('registers an onChange callback provided at construction', () => {
|
|
18
|
+
const cb = vi.fn()
|
|
19
|
+
const obs = new Observable<string>('a', cb)
|
|
20
|
+
obs.value = 'b'
|
|
21
|
+
expect(cb).toHaveBeenCalledWith('b')
|
|
22
|
+
})
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
describe('Observable — value setter', () => {
|
|
26
|
+
it('updates the stored value', () => {
|
|
27
|
+
const obs = new Observable(1)
|
|
28
|
+
obs.value = 2
|
|
29
|
+
expect(obs.value).toBe(2)
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
it('fires connected callbacks with the new value', () => {
|
|
33
|
+
const cb = vi.fn()
|
|
34
|
+
const obs = new Observable(0)
|
|
35
|
+
obs.connect(cb)
|
|
36
|
+
obs.value = 99
|
|
37
|
+
expect(cb).toHaveBeenCalledOnce()
|
|
38
|
+
expect(cb).toHaveBeenCalledWith(99)
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
it('fires all connected callbacks', () => {
|
|
42
|
+
const cb1 = vi.fn()
|
|
43
|
+
const cb2 = vi.fn()
|
|
44
|
+
const obs = new Observable(0)
|
|
45
|
+
obs.connect(cb1).connect(cb2)
|
|
46
|
+
obs.value = 1
|
|
47
|
+
expect(cb1).toHaveBeenCalledWith(1)
|
|
48
|
+
expect(cb2).toHaveBeenCalledWith(1)
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
it('does not fire callbacks when the value is unchanged', () => {
|
|
52
|
+
const cb = vi.fn()
|
|
53
|
+
const obs = new Observable('same')
|
|
54
|
+
obs.connect(cb)
|
|
55
|
+
obs.value = 'same'
|
|
56
|
+
expect(cb).not.toHaveBeenCalled()
|
|
57
|
+
})
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
describe('Observable — connect / disconnect', () => {
|
|
61
|
+
it('returns this for chaining', () => {
|
|
62
|
+
const obs = new Observable(0)
|
|
63
|
+
const cb = vi.fn()
|
|
64
|
+
expect(obs.connect(cb)).toBe(obs)
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
it('does not register the same callback twice', () => {
|
|
68
|
+
const cb = vi.fn()
|
|
69
|
+
const obs = new Observable(0)
|
|
70
|
+
obs.connect(cb).connect(cb)
|
|
71
|
+
obs.value = 1
|
|
72
|
+
expect(cb).toHaveBeenCalledOnce()
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
it('stops firing a disconnected callback', () => {
|
|
76
|
+
const cb = vi.fn()
|
|
77
|
+
const obs = new Observable(0)
|
|
78
|
+
obs.connect(cb)
|
|
79
|
+
obs.disconnect(cb)
|
|
80
|
+
obs.value = 1
|
|
81
|
+
expect(cb).not.toHaveBeenCalled()
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
it('ignores disconnect of a callback that was never connected', () => {
|
|
85
|
+
const obs = new Observable(0)
|
|
86
|
+
expect(() => obs.disconnect(vi.fn())).not.toThrow()
|
|
87
|
+
})
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
describe('Observable — pause / resume', () => {
|
|
91
|
+
it('suppresses callbacks inside the pause block', () => {
|
|
92
|
+
const cb = vi.fn()
|
|
93
|
+
const obs = new Observable(0)
|
|
94
|
+
obs.connect(cb)
|
|
95
|
+
obs.pause(() => { obs.value = 1 })
|
|
96
|
+
expect(cb).not.toHaveBeenCalled()
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
it('still updates the value during the pause block', () => {
|
|
100
|
+
const obs = new Observable(0)
|
|
101
|
+
obs.pause(() => { obs.value = 99 })
|
|
102
|
+
expect(obs.value).toBe(99)
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
it('resumes callbacks after the pause block completes', () => {
|
|
106
|
+
const cb = vi.fn()
|
|
107
|
+
const obs = new Observable(0)
|
|
108
|
+
obs.connect(cb)
|
|
109
|
+
obs.pause(() => { obs.value = 1 })
|
|
110
|
+
obs.value = 2
|
|
111
|
+
expect(cb).toHaveBeenCalledOnce()
|
|
112
|
+
expect(cb).toHaveBeenCalledWith(2)
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
it('suppresses callbacks when paused manually without a block', () => {
|
|
116
|
+
const cb = vi.fn()
|
|
117
|
+
const obs = new Observable(0)
|
|
118
|
+
obs.connect(cb)
|
|
119
|
+
obs.pause()
|
|
120
|
+
obs.value = 1
|
|
121
|
+
expect(cb).not.toHaveBeenCalled()
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
it('resumes callbacks after an explicit resume()', () => {
|
|
125
|
+
const cb = vi.fn()
|
|
126
|
+
const obs = new Observable(0)
|
|
127
|
+
obs.connect(cb)
|
|
128
|
+
obs.pause()
|
|
129
|
+
obs.resume()
|
|
130
|
+
obs.value = 1
|
|
131
|
+
expect(cb).toHaveBeenCalledWith(1)
|
|
132
|
+
})
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
describe('Observable — trigger', () => {
|
|
136
|
+
it('fires all callbacks with the current value', () => {
|
|
137
|
+
const cb = vi.fn()
|
|
138
|
+
const obs = new Observable('x')
|
|
139
|
+
obs.connect(cb)
|
|
140
|
+
obs.trigger()
|
|
141
|
+
expect(cb).toHaveBeenCalledWith('x')
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
it('does not fire callbacks when paused', () => {
|
|
145
|
+
const cb = vi.fn()
|
|
146
|
+
const obs = new Observable('x')
|
|
147
|
+
obs.connect(cb)
|
|
148
|
+
obs.pause()
|
|
149
|
+
obs.trigger()
|
|
150
|
+
expect(cb).not.toHaveBeenCalled()
|
|
151
|
+
})
|
|
152
|
+
})
|
|
153
|
+
|
|
154
|
+
describe('Observable — setSilently', () => {
|
|
155
|
+
it('updates the value without firing callbacks', () => {
|
|
156
|
+
const cb = vi.fn()
|
|
157
|
+
const obs = new Observable(0)
|
|
158
|
+
obs.connect(cb)
|
|
159
|
+
obs.setSilently(5)
|
|
160
|
+
expect(obs.value).toBe(5)
|
|
161
|
+
expect(cb).not.toHaveBeenCalled()
|
|
162
|
+
})
|
|
163
|
+
})
|
|
164
|
+
|
|
165
|
+
describe('Observable — toJSON', () => {
|
|
166
|
+
it('returns the current value', () => {
|
|
167
|
+
const obs = new Observable(42)
|
|
168
|
+
expect(obs.toJSON()).toBe(42)
|
|
169
|
+
})
|
|
170
|
+
})
|
|
171
|
+
|
|
172
|
+
describe('Observable — intercept: beforeChange', () => {
|
|
173
|
+
it('transforms the incoming value before it is applied', () => {
|
|
174
|
+
const obs = new Observable<string>('')
|
|
175
|
+
obs.intercept((_prev, current) => current.toUpperCase())
|
|
176
|
+
obs.value = 'hello'
|
|
177
|
+
expect(obs.value).toBe('HELLO')
|
|
178
|
+
})
|
|
179
|
+
|
|
180
|
+
it('passes the transformed value to callbacks', () => {
|
|
181
|
+
const cb = vi.fn()
|
|
182
|
+
const obs = new Observable<string>('')
|
|
183
|
+
obs.intercept((_prev, current) => current.trim())
|
|
184
|
+
obs.connect(cb)
|
|
185
|
+
obs.value = ' hi '
|
|
186
|
+
expect(cb).toHaveBeenCalledWith('hi')
|
|
187
|
+
})
|
|
188
|
+
|
|
189
|
+
it('blocks a change when beforeChange returns the previous value', () => {
|
|
190
|
+
const cb = vi.fn()
|
|
191
|
+
const obs = new Observable(5)
|
|
192
|
+
// reject negative numbers — return prev unchanged
|
|
193
|
+
obs.intercept((prev, current) => current < 0 ? prev : current)
|
|
194
|
+
obs.connect(cb)
|
|
195
|
+
obs.value = -1
|
|
196
|
+
expect(obs.value).toBe(5)
|
|
197
|
+
expect(cb).not.toHaveBeenCalled()
|
|
198
|
+
})
|
|
199
|
+
})
|
|
200
|
+
|
|
201
|
+
describe('Observable — intercept: afterChange', () => {
|
|
202
|
+
it('applies a post-set transformation until the value stabilizes', () => {
|
|
203
|
+
const obs = new Observable(0)
|
|
204
|
+
// clamp to [0, 100]: if already in range afterChange returns same value → loop ends
|
|
205
|
+
obs.intercept(
|
|
206
|
+
(_prev, current) => current,
|
|
207
|
+
(_prev, current) => Math.max(0, Math.min(100, current))
|
|
208
|
+
)
|
|
209
|
+
obs.value = 150
|
|
210
|
+
expect(obs.value).toBe(100)
|
|
211
|
+
})
|
|
212
|
+
|
|
213
|
+
it('fires callbacks with the afterChange result', () => {
|
|
214
|
+
const cb = vi.fn()
|
|
215
|
+
const obs = new Observable(0)
|
|
216
|
+
obs.intercept(
|
|
217
|
+
(_prev, current) => current,
|
|
218
|
+
(_prev, current) => Math.max(0, Math.min(100, current))
|
|
219
|
+
)
|
|
220
|
+
obs.connect(cb)
|
|
221
|
+
obs.value = 200
|
|
222
|
+
expect(cb).toHaveBeenLastCalledWith(100)
|
|
223
|
+
})
|
|
224
|
+
|
|
225
|
+
it('throws when afterChange never stabilizes (infinite loop guard)', () => {
|
|
226
|
+
const obs = new Observable(0)
|
|
227
|
+
obs.intercept(
|
|
228
|
+
(_prev, current) => current,
|
|
229
|
+
(_prev, current) => current + 1 // always returns a new value
|
|
230
|
+
)
|
|
231
|
+
expect(() => { obs.value = 1 }).toThrow(/afterChange exceeded depth/)
|
|
232
|
+
})
|
|
233
|
+
})
|
|
234
|
+
|
|
235
|
+
describe('Observable — re-entrant set (coalescing)', () => {
|
|
236
|
+
it('applies only the last value requested during an active callback', () => {
|
|
237
|
+
const obs = new Observable(0)
|
|
238
|
+
const calls: number[] = []
|
|
239
|
+
|
|
240
|
+
obs.connect((v) => {
|
|
241
|
+
calls.push(v)
|
|
242
|
+
if (v === 1) {
|
|
243
|
+
obs.value = 2 // queued as pending
|
|
244
|
+
obs.value = 3 // overwrites pending — only 3 should run
|
|
245
|
+
}
|
|
246
|
+
})
|
|
247
|
+
|
|
248
|
+
obs.value = 1
|
|
249
|
+
expect(obs.value).toBe(3)
|
|
250
|
+
expect(calls).toEqual([1, 3])
|
|
251
|
+
})
|
|
252
|
+
|
|
253
|
+
it('does not produce a chained set when the pending value equals current', () => {
|
|
254
|
+
const cb = vi.fn()
|
|
255
|
+
const obs = new Observable(0)
|
|
256
|
+
|
|
257
|
+
obs.connect(() => {
|
|
258
|
+
obs.value = obs.value // set to same — should be a no-op after coalescing
|
|
259
|
+
})
|
|
260
|
+
obs.connect(cb)
|
|
261
|
+
|
|
262
|
+
obs.value = 1
|
|
263
|
+
// cb fires once (for the initial set to 1); no chained set because pending === current
|
|
264
|
+
expect(cb).toHaveBeenCalledOnce()
|
|
265
|
+
})
|
|
266
|
+
})
|
|
267
|
+
|
|
268
|
+
describe('Observable — chained sets (listener-driven)', () => {
|
|
269
|
+
it('processes a value requested by a listener after the current cycle', () => {
|
|
270
|
+
const obs = new Observable(0)
|
|
271
|
+
const calls: number[] = []
|
|
272
|
+
|
|
273
|
+
obs.connect((v) => {
|
|
274
|
+
calls.push(v)
|
|
275
|
+
if (v === 1) obs.value = 2 // request one further change only
|
|
276
|
+
})
|
|
277
|
+
|
|
278
|
+
obs.value = 1
|
|
279
|
+
expect(obs.value).toBe(2)
|
|
280
|
+
expect(calls).toEqual([1, 2])
|
|
281
|
+
})
|
|
282
|
+
|
|
283
|
+
it('throws when a listener causes an infinite chain of distinct values (loop guard)', () => {
|
|
284
|
+
const obs = new Observable(0)
|
|
285
|
+
obs.connect((v) => { obs.value = v + 1 }) // always requests a different value
|
|
286
|
+
expect(() => { obs.value = 1 }).toThrow(/Too many chained set operations/)
|
|
287
|
+
})
|
|
288
|
+
})
|
|
289
|
+
|
|
290
|
+
describe('Observable — custom equals', () => {
|
|
291
|
+
it('uses the provided comparator to decide whether the value changed', () => {
|
|
292
|
+
const cb = vi.fn()
|
|
293
|
+
const obs = new Observable<string>('hello', undefined, (a, b) => a?.toLowerCase() === b?.toLowerCase())
|
|
294
|
+
obs.connect(cb)
|
|
295
|
+
obs.value = 'HELLO' // equal by custom comparator → no change
|
|
296
|
+
expect(cb).not.toHaveBeenCalled()
|
|
297
|
+
expect(obs.value).toBe('hello')
|
|
298
|
+
})
|
|
299
|
+
})
|
|
300
|
+
|
|
301
|
+
// ─── BooleanObservable ────────────────────────────────────────────────────────
|
|
302
|
+
|
|
303
|
+
describe('Observable — resilience: callback throws', () => {
|
|
304
|
+
it('remains usable after a callback throws', () => {
|
|
305
|
+
const obs = new Observable(0)
|
|
306
|
+
const boom = () => { throw new Error('boom') }
|
|
307
|
+
obs.connect(boom)
|
|
308
|
+
expect(() => { obs.value = 1 }).toThrow('boom')
|
|
309
|
+
|
|
310
|
+
// disconnect the bad callback, then confirm _isSetting was cleared
|
|
311
|
+
obs.disconnect(boom)
|
|
312
|
+
const cb = vi.fn()
|
|
313
|
+
obs.connect(cb)
|
|
314
|
+
obs.value = 2
|
|
315
|
+
expect(cb).toHaveBeenCalledWith(2)
|
|
316
|
+
})
|
|
317
|
+
|
|
318
|
+
it('resumes notifications after the pause block throws', () => {
|
|
319
|
+
const cb = vi.fn()
|
|
320
|
+
const obs = new Observable(0)
|
|
321
|
+
obs.connect(cb)
|
|
322
|
+
expect(() => obs.pause(() => { throw new Error('boom') })).toThrow('boom')
|
|
323
|
+
|
|
324
|
+
// _paused must be false so future changes still fire callbacks
|
|
325
|
+
obs.value = 1
|
|
326
|
+
expect(cb).toHaveBeenCalledWith(1)
|
|
327
|
+
})
|
|
328
|
+
})
|
|
329
|
+
|
|
330
|
+
describe('Observable — subscriber list mutation during fire', () => {
|
|
331
|
+
it('does not call a callback that disconnects itself during the current fire', () => {
|
|
332
|
+
const obs = new Observable(0)
|
|
333
|
+
const calls: string[] = []
|
|
334
|
+
|
|
335
|
+
const selfRemove = () => {
|
|
336
|
+
calls.push('selfRemove')
|
|
337
|
+
obs.disconnect(selfRemove)
|
|
338
|
+
}
|
|
339
|
+
const other = () => calls.push('other')
|
|
340
|
+
|
|
341
|
+
obs.connect(selfRemove).connect(other)
|
|
342
|
+
obs.value = 1
|
|
343
|
+
|
|
344
|
+
expect(calls).toEqual(['selfRemove', 'other'])
|
|
345
|
+
|
|
346
|
+
// selfRemove was disconnected — should not fire on the next change
|
|
347
|
+
calls.length = 0
|
|
348
|
+
obs.value = 2
|
|
349
|
+
expect(calls).toEqual(['other'])
|
|
350
|
+
})
|
|
351
|
+
|
|
352
|
+
it('does not call a callback added during the current fire', () => {
|
|
353
|
+
const obs = new Observable(0)
|
|
354
|
+
const late = vi.fn()
|
|
355
|
+
|
|
356
|
+
obs.connect(() => { obs.connect(late) })
|
|
357
|
+
obs.value = 1
|
|
358
|
+
|
|
359
|
+
// late was added mid-fire from a snapshot, should not have been called yet
|
|
360
|
+
expect(late).not.toHaveBeenCalled()
|
|
361
|
+
|
|
362
|
+
// but it is registered for future changes
|
|
363
|
+
obs.value = 2
|
|
364
|
+
expect(late).toHaveBeenCalledWith(2)
|
|
365
|
+
})
|
|
366
|
+
})
|
|
367
|
+
|
|
368
|
+
describe('BooleanObservable — combine', () => {
|
|
369
|
+
it('initializes to true when all combined observables are true', () => {
|
|
370
|
+
const a = new BooleanObservable(true)
|
|
371
|
+
const b = new BooleanObservable(true)
|
|
372
|
+
const combined = new BooleanObservable()
|
|
373
|
+
combined.combine(a, b)
|
|
374
|
+
expect(combined.value).toBe(true)
|
|
375
|
+
})
|
|
376
|
+
|
|
377
|
+
it('initializes to false when any combined observable is false', () => {
|
|
378
|
+
const a = new BooleanObservable(true)
|
|
379
|
+
const b = new BooleanObservable(false)
|
|
380
|
+
const combined = new BooleanObservable()
|
|
381
|
+
combined.combine(a, b)
|
|
382
|
+
expect(combined.value).toBe(false)
|
|
383
|
+
})
|
|
384
|
+
|
|
385
|
+
it('updates to false when a combined observable becomes false', () => {
|
|
386
|
+
const a = new BooleanObservable(true)
|
|
387
|
+
const b = new BooleanObservable(true)
|
|
388
|
+
const combined = new BooleanObservable()
|
|
389
|
+
combined.combine(a, b)
|
|
390
|
+
b.value = false
|
|
391
|
+
expect(combined.value).toBe(false)
|
|
392
|
+
})
|
|
393
|
+
|
|
394
|
+
it('updates to true when all combined observables become true', () => {
|
|
395
|
+
const a = new BooleanObservable(true)
|
|
396
|
+
const b = new BooleanObservable(false)
|
|
397
|
+
const combined = new BooleanObservable()
|
|
398
|
+
combined.combine(a, b)
|
|
399
|
+
b.value = true
|
|
400
|
+
expect(combined.value).toBe(true)
|
|
401
|
+
})
|
|
402
|
+
|
|
403
|
+
it('throws when attempting to combine with itself', () => {
|
|
404
|
+
const obs = new BooleanObservable(true)
|
|
405
|
+
expect(() => obs.combine(obs)).toThrow('Cannot combine with itself')
|
|
406
|
+
})
|
|
407
|
+
|
|
408
|
+
it('does not stack overflow or throw when combined observables change (circular guard)', () => {
|
|
409
|
+
const a = new BooleanObservable(true)
|
|
410
|
+
const b = new BooleanObservable(true)
|
|
411
|
+
const combined = new BooleanObservable()
|
|
412
|
+
combined.combine(a, b)
|
|
413
|
+
expect(() => { a.value = false }).not.toThrow()
|
|
414
|
+
expect(combined.value).toBe(false)
|
|
415
|
+
})
|
|
416
|
+
})
|
package/src/lib/observable.ts
CHANGED
|
@@ -40,24 +40,25 @@ export class Observable<T> {
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
this._isSetting = true;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
// Apply afterChange transformations (bounded)
|
|
47
|
-
let transformed = this._afterChange?.(prev, this._value);
|
|
48
|
-
while (transformed !== undefined && !this._equals(this._value, transformed)) {
|
|
49
|
-
afterDepth++;
|
|
50
|
-
if (afterDepth > Observable.MAX_AFTER_CHANGE_DEPTH) {
|
|
51
|
-
this._isSetting = false;
|
|
52
|
-
this._pendingValue = undefined;
|
|
53
|
-
throw new Error(`Observable: _afterChange exceeded depth ${Observable.MAX_AFTER_CHANGE_DEPTH}. Possible loop.`);
|
|
54
|
-
}
|
|
55
|
-
this._value = transformed;
|
|
43
|
+
try {
|
|
44
|
+
this._value = candidate;
|
|
56
45
|
if (!this._paused) this._onChange.slice().forEach(cb => cb(this._value));
|
|
57
|
-
transformed = this._afterChange?.(prev, this._value);
|
|
58
|
-
}
|
|
59
46
|
|
|
60
|
-
|
|
47
|
+
// Apply afterChange transformations (bounded)
|
|
48
|
+
let transformed = this._afterChange?.(prev, this._value);
|
|
49
|
+
while (transformed !== undefined && !this._equals(this._value, transformed)) {
|
|
50
|
+
afterDepth++;
|
|
51
|
+
if (afterDepth > Observable.MAX_AFTER_CHANGE_DEPTH) {
|
|
52
|
+
this._pendingValue = undefined;
|
|
53
|
+
throw new Error(`Observable: _afterChange exceeded depth ${Observable.MAX_AFTER_CHANGE_DEPTH}. Possible loop.`);
|
|
54
|
+
}
|
|
55
|
+
this._value = transformed;
|
|
56
|
+
if (!this._paused) this._onChange.slice().forEach(cb => cb(this._value));
|
|
57
|
+
transformed = this._afterChange?.(prev, this._value);
|
|
58
|
+
}
|
|
59
|
+
} finally {
|
|
60
|
+
this._isSetting = false;
|
|
61
|
+
}
|
|
61
62
|
|
|
62
63
|
// If a listener requested a new value during this cycle, process it
|
|
63
64
|
if (this._pendingValue !== undefined && !this._equals(this._value, this._pendingValue)) {
|
|
@@ -99,8 +100,13 @@ export class Observable<T> {
|
|
|
99
100
|
|
|
100
101
|
pause(callback?: () => void): void {
|
|
101
102
|
this._paused = true;
|
|
102
|
-
callback
|
|
103
|
-
|
|
103
|
+
if (callback !== undefined) {
|
|
104
|
+
try {
|
|
105
|
+
callback();
|
|
106
|
+
} finally {
|
|
107
|
+
this.resume();
|
|
108
|
+
}
|
|
109
|
+
}
|
|
104
110
|
}
|
|
105
111
|
resume(): void { this._paused = false; }
|
|
106
112
|
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
import { TreeNode } from './tree-node'
|
|
3
|
+
|
|
4
|
+
describe('TreeNode.values', () => {
|
|
5
|
+
it('returns values in depth-first order and skips null nodes', () => {
|
|
6
|
+
const tree = new TreeNode('root', '', null, [
|
|
7
|
+
new TreeNode('menu', '/menu', { name: 'menu' }, [
|
|
8
|
+
new TreeNode('action-a', '/menu/action-a', { name: 'action-a' }),
|
|
9
|
+
new TreeNode('group', '/menu/group', null, [
|
|
10
|
+
new TreeNode('action-b', '/menu/group/action-b', { name: 'action-b' })
|
|
11
|
+
])
|
|
12
|
+
])
|
|
13
|
+
])
|
|
14
|
+
|
|
15
|
+
expect(tree.values()).toEqual([
|
|
16
|
+
{ name: 'menu' },
|
|
17
|
+
{ name: 'action-a' },
|
|
18
|
+
{ name: 'action-b' }
|
|
19
|
+
])
|
|
20
|
+
})
|
|
21
|
+
})
|
package/tsconfig.json
CHANGED
|
@@ -1,125 +1,41 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
/* Projects */
|
|
6
|
-
// "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
|
|
7
|
-
// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
|
|
8
|
-
// "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
|
|
9
|
-
// "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
|
|
10
|
-
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
|
|
11
|
-
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
|
|
12
|
-
|
|
13
|
-
/* Language and Environment */
|
|
14
|
-
"target": "ES5" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
|
|
15
|
-
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
|
|
3
|
+
"target": "ES5",
|
|
4
|
+
"ignoreDeprecations": "5.0",
|
|
16
5
|
"lib": ["ES5"],
|
|
17
|
-
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
// "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
|
|
23
|
-
// "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
|
|
24
|
-
"noLib": false /* Disable including any library files, including the default lib.d.ts. */,
|
|
25
|
-
"useDefineForClassFields": false /* Emit ECMAScript-standard-compliant class fields. */,
|
|
26
|
-
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
|
|
27
|
-
|
|
28
|
-
/* Modules */
|
|
29
|
-
"module": "ESNext" /* Specify what module code is generated. */,
|
|
30
|
-
// "rootDir": "./", /* Specify the root folder within your source files. */
|
|
31
|
-
//"moduleResolution": "Node" /* Specify how TypeScript looks up a file from a given module specifier. */,
|
|
32
|
-
"baseUrl": "./" /* Specify the base directory to resolve non-relative module names. */,
|
|
6
|
+
"experimentalDecorators": true,
|
|
7
|
+
"emitDecoratorMetadata": true,
|
|
8
|
+
"noLib": false,
|
|
9
|
+
"useDefineForClassFields": false,
|
|
10
|
+
"module": "ESNext",
|
|
33
11
|
"paths": {
|
|
34
|
-
"shared/*": ["src/shared/*"],
|
|
12
|
+
"shared/*": ["./src/shared/*"],
|
|
35
13
|
"@dst/*": [
|
|
36
|
-
"
|
|
14
|
+
"../script-types/src/types/*",
|
|
37
15
|
"../node_modules/dazscript-types/src/types/*",
|
|
38
|
-
"
|
|
16
|
+
"./node_modules/dazscript-types/src/types/*"
|
|
39
17
|
],
|
|
40
|
-
"@dsf/*": ["src/*"]
|
|
18
|
+
"@dsf/*": ["./src/*"]
|
|
41
19
|
},
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
/* JavaScript Support */
|
|
57
|
-
// "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
|
|
58
|
-
// "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
|
|
59
|
-
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
|
|
60
|
-
|
|
61
|
-
/* Emit */
|
|
62
|
-
"declaration": false /* Generate .d.ts files from TypeScript and JavaScript files in your project. */,
|
|
63
|
-
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
|
|
64
|
-
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
|
|
65
|
-
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
|
|
66
|
-
"inlineSourceMap": false /* Include sourcemap files inside the emitted JavaScript. */,
|
|
67
|
-
// "outFile": "./dist/sandbox.dsa" /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */,
|
|
68
|
-
// "outDir": "./", /* Specify an output folder for all emitted files. */
|
|
69
|
-
"removeComments": true /* Disable emitting comments. */,
|
|
70
|
-
//"noEmit": true /* Disable emitting files from a compilation. */,
|
|
71
|
-
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
|
|
72
|
-
// "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */
|
|
73
|
-
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
|
|
74
|
-
// "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
|
|
75
|
-
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
|
76
|
-
// "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
|
|
77
|
-
// "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
|
|
78
|
-
// "newLine": "crlf", /* Set the newline character for emitting files. */
|
|
79
|
-
// "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
|
|
80
|
-
// "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
|
|
81
|
-
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
|
|
82
|
-
"preserveConstEnums": true /* Disable erasing 'const enum' declarations in generated code. */,
|
|
83
|
-
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
|
|
84
|
-
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
|
|
85
|
-
|
|
86
|
-
/* Interop Constraints */
|
|
87
|
-
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
|
|
88
|
-
// "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */
|
|
89
|
-
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
|
|
90
|
-
"esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
|
|
91
|
-
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
|
|
92
|
-
"forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
|
|
93
|
-
|
|
94
|
-
/* Type Checking */
|
|
95
|
-
// "strict": true, /* Enable all strict type-checking options. */
|
|
96
|
-
"noImplicitAny": false /* Enable error reporting for expressions and declarations with an implied 'any' type. */,
|
|
97
|
-
// "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
|
|
98
|
-
"strictFunctionTypes": true /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */,
|
|
99
|
-
//"strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
|
|
100
|
-
// "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
|
|
101
|
-
// "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
|
|
102
|
-
// "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
|
|
103
|
-
"alwaysStrict": true /* Ensure 'use strict' is always emitted. */,
|
|
104
|
-
// "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
|
|
105
|
-
// "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
|
|
106
|
-
// "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
|
|
107
|
-
// "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
|
|
108
|
-
// "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
|
|
109
|
-
// "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
|
|
110
|
-
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
|
|
111
|
-
// "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
|
|
112
|
-
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
|
|
113
|
-
// "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
|
|
114
|
-
|
|
115
|
-
/* Completeness */
|
|
116
|
-
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
|
|
117
|
-
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
|
20
|
+
"declaration": false,
|
|
21
|
+
"inlineSourceMap": false,
|
|
22
|
+
"removeComments": true,
|
|
23
|
+
"preserveConstEnums": true,
|
|
24
|
+
"esModuleInterop": true,
|
|
25
|
+
"forceConsistentCasingInFileNames": true,
|
|
26
|
+
"strict": false,
|
|
27
|
+
"strictNullChecks": false,
|
|
28
|
+
"strictPropertyInitialization": false,
|
|
29
|
+
"noImplicitAny": false,
|
|
30
|
+
"strictFunctionTypes": true,
|
|
31
|
+
"alwaysStrict": true,
|
|
32
|
+
"skipLibCheck": true
|
|
118
33
|
},
|
|
119
34
|
"include": [
|
|
120
|
-
"node_modules/dazscript-types/src/types/**/*",
|
|
121
|
-
"../node_modules/dazscript-types/src/types/**/*",
|
|
122
35
|
"../script-types/src/types/**/*",
|
|
36
|
+
"../node_modules/dazscript-types/src/types/**/*",
|
|
37
|
+
"node_modules/dazscript-types/src/types/**/*",
|
|
123
38
|
"src/**/*"
|
|
124
|
-
]
|
|
39
|
+
],
|
|
40
|
+
"exclude": ["src/**/*.test.ts"]
|
|
125
41
|
}
|