@softwarity/livewire 0.1.1 → 0.2.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 +9 -14
- package/fesm2022/softwarity-livewire.mjs +723 -0
- package/fesm2022/softwarity-livewire.mjs.map +1 -0
- package/index.d.ts +5 -0
- package/lib/live-indicator.component.d.ts +36 -0
- package/lib/live-list.d.ts +36 -0
- package/lib/live-topic.d.ts +51 -0
- package/lib/live-window.datasource.d.ts +122 -0
- package/lib/livewire.client.d.ts +99 -0
- package/{src/lib/provide-livewire.ts → lib/provide-livewire.d.ts} +1 -5
- package/package.json +15 -25
- package/{src/public-api.ts → public-api.d.ts} +1 -13
- package/jest.config.js +0 -11
- package/ng-package.json +0 -6
- package/src/lib/live-indicator.component.ts +0 -118
- package/src/lib/live-list.ts +0 -94
- package/src/lib/live-topic.ts +0 -83
- package/src/lib/live-window.datasource.ts +0 -364
- package/src/lib/livewire.client.ts +0 -215
- package/test/end-to-end.spec.ts +0 -166
- package/test/live-window.datasource.spec.ts +0 -221
- package/test/repaint.spec.ts +0 -226
- package/test/setup.ts +0 -6
- package/tsconfig.json +0 -18
- package/tsconfig.spec.json +0 -5
package/test/repaint.spec.ts
DELETED
|
@@ -1,226 +0,0 @@
|
|
|
1
|
-
import { ChangeDetectorRef, Component, inject } from '@angular/core';
|
|
2
|
-
import { TestBed } from '@angular/core/testing';
|
|
3
|
-
import { Subject } from 'rxjs';
|
|
4
|
-
import { LiveWindowDataSource } from '../src/lib/live-window.datasource';
|
|
5
|
-
import type { LiveRow, UpdateFrame } from '@softwarity/livewire-protocol';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* What repaints a zoneless screen when a frame lands in a socket callback.
|
|
9
|
-
*
|
|
10
|
-
* Two ways, and the point of this file is that the second one works: a signal
|
|
11
|
-
* the template reads, or a `ChangeDetectorRef` handed to the data source.
|
|
12
|
-
*
|
|
13
|
-
* The templates here read **no signal at all** and use no async pipe - they
|
|
14
|
-
* render a plain field, filled from a subscription. That is deliberate: it
|
|
15
|
-
* strips out every other thing that could schedule a pass, so what the test
|
|
16
|
-
* measures is the notification itself and nothing else.
|
|
17
|
-
*/
|
|
18
|
-
describe('repainting a zoneless screen', () => {
|
|
19
|
-
const feed = new Subject<UpdateFrame<LiveRow>>();
|
|
20
|
-
|
|
21
|
-
function frame(...ids: string[]): UpdateFrame<LiveRow> {
|
|
22
|
-
return {
|
|
23
|
-
id: 'w',
|
|
24
|
-
type: 'snapshot',
|
|
25
|
-
rows: ids.map((id) => ({ id, updatedAt: 'v1' })),
|
|
26
|
-
total: ids.length,
|
|
27
|
-
sequence: 1,
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
@Component({
|
|
32
|
-
selector: 'test-told',
|
|
33
|
-
standalone: true,
|
|
34
|
-
template: `<span class="ids">{{ ids }}</span>`,
|
|
35
|
-
})
|
|
36
|
-
class ToldComponent {
|
|
37
|
-
ids = '';
|
|
38
|
-
|
|
39
|
-
readonly source = new LiveWindowDataSource<LiveRow>(
|
|
40
|
-
() => undefined,
|
|
41
|
-
() => undefined,
|
|
42
|
-
100,
|
|
43
|
-
inject(ChangeDetectorRef),
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
constructor() {
|
|
47
|
-
this.source.changes.subscribe((rows) => (this.ids = rows.map((row) => row?.id ?? '-').join(',')));
|
|
48
|
-
this.source.reset(() => feed);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
@Component({
|
|
53
|
-
selector: 'test-silent',
|
|
54
|
-
standalone: true,
|
|
55
|
-
template: `<span class="ids">{{ ids }}</span>`,
|
|
56
|
-
})
|
|
57
|
-
class SilentComponent {
|
|
58
|
-
ids = '';
|
|
59
|
-
|
|
60
|
-
readonly source = new LiveWindowDataSource<LiveRow>();
|
|
61
|
-
|
|
62
|
-
constructor() {
|
|
63
|
-
this.source.changes.subscribe((rows) => (this.ids = rows.map((row) => row?.id ?? '-').join(',')));
|
|
64
|
-
this.source.reset(() => feed);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
it('repaints on its own when it was given a ChangeDetectorRef', async () => {
|
|
69
|
-
const fixture = TestBed.createComponent(ToldComponent);
|
|
70
|
-
await fixture.whenStable();
|
|
71
|
-
|
|
72
|
-
// Straight into the data source, as a socket callback would - nothing here
|
|
73
|
-
// runs inside a change-detection cycle.
|
|
74
|
-
feed.next(frame('a', 'b'));
|
|
75
|
-
await fixture.whenStable();
|
|
76
|
-
|
|
77
|
-
expect(fixture.nativeElement.querySelector('.ids').textContent).toBe('a,b');
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* The other half of the claim, and the reason the rule exists: without either
|
|
82
|
-
* notification the field is right and the screen is wrong. A test that only
|
|
83
|
-
* checked the first case would pass just as well if something else in the
|
|
84
|
-
* fixture were scheduling the pass.
|
|
85
|
-
*/
|
|
86
|
-
it('does not, when it was given neither a ChangeDetectorRef nor a revision() read', async () => {
|
|
87
|
-
const fixture = TestBed.createComponent(SilentComponent);
|
|
88
|
-
await fixture.whenStable();
|
|
89
|
-
|
|
90
|
-
feed.next(frame('a', 'b'));
|
|
91
|
-
await fixture.whenStable();
|
|
92
|
-
|
|
93
|
-
expect(fixture.componentInstance.ids).toBe('a,b');
|
|
94
|
-
expect(fixture.nativeElement.querySelector('.ids').textContent).toBe('');
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it('repaints again on every later frame, not only the first', async () => {
|
|
98
|
-
const fixture = TestBed.createComponent(ToldComponent);
|
|
99
|
-
await fixture.whenStable();
|
|
100
|
-
|
|
101
|
-
for (const ids of [['a'], ['a', 'b'], ['a', 'b', 'c']]) {
|
|
102
|
-
feed.next(frame(...ids));
|
|
103
|
-
await fixture.whenStable();
|
|
104
|
-
expect(fixture.nativeElement.querySelector('.ids').textContent).toBe(ids.join(','));
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* The other half of "it repaints": that it does so only when there is something
|
|
111
|
-
* to repaint.
|
|
112
|
-
*
|
|
113
|
-
* A pass asked for on every read rather than on every change is how a live
|
|
114
|
-
* screen becomes one nobody can use - and it would be invisible, since the
|
|
115
|
-
* screen would look right the whole time.
|
|
116
|
-
*/
|
|
117
|
-
describe('what asks for a repaint, and what does not', () => {
|
|
118
|
-
let asked: number;
|
|
119
|
-
let repaint: ChangeDetectorRef;
|
|
120
|
-
let feed: Subject<UpdateFrame<LiveRow>>;
|
|
121
|
-
let source: LiveWindowDataSource<LiveRow>;
|
|
122
|
-
|
|
123
|
-
function rows(count: number): LiveRow[] {
|
|
124
|
-
return Array.from({ length: count }, (_, index) => ({ id: `r${index}`, updatedAt: 'v1' }));
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
beforeEach(() => {
|
|
128
|
-
jest.useFakeTimers();
|
|
129
|
-
asked = 0;
|
|
130
|
-
// Only `markForCheck` is ever called; the rest of the interface is not
|
|
131
|
-
// worth stubbing to count one thing.
|
|
132
|
-
repaint = { markForCheck: () => (asked += 1) } as unknown as ChangeDetectorRef;
|
|
133
|
-
feed = new Subject<UpdateFrame<LiveRow>>();
|
|
134
|
-
source = new LiveWindowDataSource<LiveRow>(
|
|
135
|
-
() => undefined,
|
|
136
|
-
() => undefined,
|
|
137
|
-
100,
|
|
138
|
-
repaint,
|
|
139
|
-
);
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
afterEach(() => jest.useRealTimers());
|
|
143
|
-
|
|
144
|
-
it('asks once when the list is emptied for a new question', () => {
|
|
145
|
-
source.reset(() => feed);
|
|
146
|
-
|
|
147
|
-
expect(asked).toBe(1);
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* A screen calls `reset` from an `effect`, and Angular 18 refuses a signal
|
|
152
|
-
* write from inside one. So emptying the list asks for a pass without
|
|
153
|
-
* touching `revision` - which stays where the frames bump it.
|
|
154
|
-
*/
|
|
155
|
-
it('empties the list without writing a signal', () => {
|
|
156
|
-
const before = source.revision();
|
|
157
|
-
|
|
158
|
-
source.reset(() => feed);
|
|
159
|
-
|
|
160
|
-
expect(source.revision()).toBe(before);
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
it('asks once per frame it could apply, and no more', () => {
|
|
164
|
-
source.reset(() => feed);
|
|
165
|
-
asked = 0;
|
|
166
|
-
|
|
167
|
-
feed.next({ id: 'w', type: 'snapshot', rows: rows(3), total: 3, sequence: 1 });
|
|
168
|
-
expect(asked).toBe(1);
|
|
169
|
-
|
|
170
|
-
feed.next({
|
|
171
|
-
id: 'w',
|
|
172
|
-
type: 'patch',
|
|
173
|
-
upserted: [{ id: 'new', updatedAt: 'v1' }],
|
|
174
|
-
removed: [],
|
|
175
|
-
order: ['new', 'r0', 'r1', 'r2'],
|
|
176
|
-
total: 4,
|
|
177
|
-
sequence: 2,
|
|
178
|
-
});
|
|
179
|
-
expect(asked).toBe(2);
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
/** A frame it cannot place changes nothing on the screen. It resyncs instead. */
|
|
183
|
-
it('asks for nothing on a frame it had to reject', () => {
|
|
184
|
-
source.reset(() => feed);
|
|
185
|
-
feed.next({ id: 'w', type: 'snapshot', rows: rows(3), total: 3, sequence: 1 });
|
|
186
|
-
asked = 0;
|
|
187
|
-
|
|
188
|
-
// Sequence 3 where 2 was due.
|
|
189
|
-
feed.next({ id: 'w', type: 'patch', upserted: [], removed: [], order: ['r0'], total: 1, sequence: 3 });
|
|
190
|
-
|
|
191
|
-
expect(asked).toBe(0);
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
/** Moving the window is a question, not an answer. The snapshot repaints. */
|
|
195
|
-
it('asks for nothing when the window moves, only when its answer lands', () => {
|
|
196
|
-
source.reset(() => feed);
|
|
197
|
-
feed.next({ id: 'w', type: 'snapshot', rows: rows(100), total: 13_000, sequence: 1 });
|
|
198
|
-
asked = 0;
|
|
199
|
-
|
|
200
|
-
source.ensure(9000);
|
|
201
|
-
|
|
202
|
-
expect(asked).toBe(0);
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
/** The marks have to come off, and taking them off is a change like any other. */
|
|
206
|
-
it('asks once more when the fresh marks expire, and then stops', () => {
|
|
207
|
-
source.reset(() => feed);
|
|
208
|
-
feed.next({ id: 'w', type: 'snapshot', rows: rows(3), total: 3, sequence: 1 });
|
|
209
|
-
feed.next({
|
|
210
|
-
id: 'w',
|
|
211
|
-
type: 'patch',
|
|
212
|
-
upserted: [{ id: 'new', updatedAt: 'v1' }],
|
|
213
|
-
removed: [],
|
|
214
|
-
order: ['new', 'r0', 'r1', 'r2'],
|
|
215
|
-
total: 4,
|
|
216
|
-
sequence: 2,
|
|
217
|
-
});
|
|
218
|
-
asked = 0;
|
|
219
|
-
|
|
220
|
-
jest.advanceTimersByTime(1000);
|
|
221
|
-
expect(asked).toBe(1);
|
|
222
|
-
|
|
223
|
-
jest.advanceTimersByTime(10_000);
|
|
224
|
-
expect(asked).toBe(1);
|
|
225
|
-
});
|
|
226
|
-
});
|
package/test/setup.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
// Zoneless, deliberately: this library is written for applications that do not
|
|
2
|
-
// ship zone.js, and its one contract with change detection - read `revision()`
|
|
3
|
-
// in the template - only means anything there.
|
|
4
|
-
import { setupZonelessTestEnv } from 'jest-preset-angular/setup-env/zoneless';
|
|
5
|
-
|
|
6
|
-
setupZonelessTestEnv();
|
package/tsconfig.json
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2022",
|
|
4
|
-
"module": "ES2022",
|
|
5
|
-
"moduleResolution": "bundler",
|
|
6
|
-
"lib": ["ES2022", "DOM"],
|
|
7
|
-
"declaration": true,
|
|
8
|
-
"experimentalDecorators": true,
|
|
9
|
-
"importHelpers": true,
|
|
10
|
-
"strict": true,
|
|
11
|
-
"noImplicitOverride": true,
|
|
12
|
-
"skipLibCheck": true,
|
|
13
|
-
"esModuleInterop": true,
|
|
14
|
-
"forceConsistentCasingInFileNames": true
|
|
15
|
-
},
|
|
16
|
-
"angularCompilerOptions": { "strictTemplates": true },
|
|
17
|
-
"include": ["src/**/*.ts"]
|
|
18
|
-
}
|