@typed/template 0.5.3 → 0.6.0
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/dist/cjs/RenderContext.js.map +1 -1
- package/dist/cjs/internal/EventSource.js.map +1 -1
- package/dist/cjs/internal/indexRefCounter.js.map +1 -1
- package/dist/cjs/internal/parts.js.map +1 -1
- package/dist/cjs/internal/render.js +3 -2
- package/dist/cjs/internal/render.js.map +1 -1
- package/dist/cjs/internal/server.js.map +1 -1
- package/dist/dts/Directive.d.ts +12 -12
- package/dist/dts/Directive.d.ts.map +1 -1
- package/dist/dts/ElementRef.d.ts +5 -5
- package/dist/dts/ElementRef.d.ts.map +1 -1
- package/dist/dts/ElementSource.d.ts +1 -1
- package/dist/dts/ElementSource.d.ts.map +1 -1
- package/dist/dts/EventHandler.d.ts +7 -7
- package/dist/dts/EventHandler.d.ts.map +1 -1
- package/dist/dts/Html.d.ts +1 -1
- package/dist/dts/Html.d.ts.map +1 -1
- package/dist/dts/Hydrate.d.ts +1 -1
- package/dist/dts/Many.d.ts +2 -2
- package/dist/dts/Many.d.ts.map +1 -1
- package/dist/dts/Part.d.ts +13 -13
- package/dist/dts/Part.d.ts.map +1 -1
- package/dist/dts/Placeholder.d.ts +1 -1
- package/dist/dts/Placeholder.d.ts.map +1 -1
- package/dist/dts/Platform.d.ts +1 -1
- package/dist/dts/Platform.d.ts.map +1 -1
- package/dist/dts/Render.d.ts +1 -1
- package/dist/dts/Render.d.ts.map +1 -1
- package/dist/dts/RenderContext.d.ts +5 -5
- package/dist/dts/RenderContext.d.ts.map +1 -1
- package/dist/dts/Renderable.d.ts +1 -1
- package/dist/dts/Renderable.d.ts.map +1 -1
- package/dist/dts/Test.d.ts +8 -8
- package/dist/dts/Test.d.ts.map +1 -1
- package/dist/dts/Vitest.d.ts +2 -2
- package/dist/dts/Vitest.d.ts.map +1 -1
- package/dist/dts/internal/EventSource.d.ts +1 -1
- package/dist/dts/internal/EventSource.d.ts.map +1 -1
- package/dist/dts/internal/indexRefCounter.d.ts +5 -5
- package/dist/dts/internal/indexRefCounter.d.ts.map +1 -1
- package/dist/dts/internal/parts.d.ts +38 -38
- package/dist/dts/internal/parts.d.ts.map +1 -1
- package/dist/dts/internal/render.d.ts +1 -1
- package/dist/dts/internal/render.d.ts.map +1 -1
- package/dist/dts/internal/server.d.ts +2 -2
- package/dist/dts/internal/server.d.ts.map +1 -1
- package/dist/dts/internal/utils.d.ts +1 -1
- package/dist/esm/RenderContext.js.map +1 -1
- package/dist/esm/internal/EventSource.js.map +1 -1
- package/dist/esm/internal/indexRefCounter.js.map +1 -1
- package/dist/esm/internal/parts.js +4 -4
- package/dist/esm/internal/parts.js.map +1 -1
- package/dist/esm/internal/render.js +3 -2
- package/dist/esm/internal/render.js.map +1 -1
- package/dist/esm/internal/server.js.map +1 -1
- package/package.json +8 -16
- package/src/Directive.ts +13 -13
- package/src/ElementRef.ts +5 -5
- package/src/ElementSource.ts +2 -2
- package/src/EventHandler.ts +7 -7
- package/src/Html.ts +2 -2
- package/src/Many.ts +3 -3
- package/src/Part.ts +13 -13
- package/src/Placeholder.ts +2 -2
- package/src/Platform.ts +1 -1
- package/src/Render.ts +2 -2
- package/src/RenderContext.ts +8 -8
- package/src/Renderable.ts +1 -1
- package/src/Test.ts +6 -6
- package/src/Vitest.ts +2 -2
- package/src/internal/EventSource.ts +3 -3
- package/src/internal/hydrate.ts +2 -2
- package/src/internal/indexRefCounter.ts +9 -17
- package/src/internal/parts.ts +60 -62
- package/src/internal/render.ts +21 -20
- package/src/internal/server.ts +8 -8
- package/TemplateInstance/package.json +0 -6
- package/dist/cjs/TemplateInstance.js +0 -51
- package/dist/cjs/TemplateInstance.js.map +0 -1
- package/dist/dts/TemplateInstance.d.ts +0 -33
- package/dist/dts/TemplateInstance.d.ts.map +0 -1
- package/dist/esm/TemplateInstance.js +0 -43
- package/dist/esm/TemplateInstance.js.map +0 -1
- package/src/TemplateInstance.ts +0 -83
package/src/Render.ts
CHANGED
|
@@ -42,9 +42,9 @@ export function render<R, E, T extends RenderEvent | null>(
|
|
|
42
42
|
export function renderLayer<R, E, T extends RenderEvent | null>(
|
|
43
43
|
rendered: Fx.Fx<R, E, T>
|
|
44
44
|
): Layer.Layer<
|
|
45
|
-
Document | RenderContext | RootElement | Exclude<Exclude<R, RenderTemplate>, Scope.Scope>,
|
|
46
45
|
never,
|
|
47
|
-
never
|
|
46
|
+
never,
|
|
47
|
+
Document | RenderContext | RootElement | Exclude<Exclude<R, RenderTemplate>, Scope.Scope>
|
|
48
48
|
> {
|
|
49
49
|
return Fx.drainLayer(Fx.switchMapCause(render(rendered), (e) => Fx.fromEffect(Effect.logError(e))))
|
|
50
50
|
}
|
package/src/RenderContext.ts
CHANGED
|
@@ -57,7 +57,7 @@ export const RenderContext: Context.Tagged<RenderContext, RenderContext> = Conte
|
|
|
57
57
|
* @since 1.0.0
|
|
58
58
|
*/
|
|
59
59
|
export interface RenderQueue {
|
|
60
|
-
readonly add: (part: unknown, task: () => void) => Effect.Effect<
|
|
60
|
+
readonly add: (part: unknown, task: () => void) => Effect.Effect<void, never, Scope.Scope>
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
/**
|
|
@@ -120,7 +120,7 @@ const buildWithCurrentEnvironment = (environment: Environment, skipRenderSchedul
|
|
|
120
120
|
export const dom: (
|
|
121
121
|
window: Window & GlobalThis,
|
|
122
122
|
options?: DomServicesElementParams & { readonly skipRenderScheduling?: boolean }
|
|
123
|
-
) => Layer.Layer<
|
|
123
|
+
) => Layer.Layer<RenderContext | CurrentEnvironment | DomServices> = (window, options) =>
|
|
124
124
|
Layer.provideMerge(
|
|
125
125
|
Layer.mergeAll(
|
|
126
126
|
buildWithCurrentEnvironment(
|
|
@@ -135,11 +135,11 @@ export const dom: (
|
|
|
135
135
|
/**
|
|
136
136
|
* @since 1.0.0
|
|
137
137
|
*/
|
|
138
|
-
export const server: Layer.Layer<
|
|
138
|
+
export const server: Layer.Layer<RenderContext | CurrentEnvironment> = buildWithCurrentEnvironment(
|
|
139
139
|
"server"
|
|
140
140
|
)
|
|
141
141
|
|
|
142
|
-
const static_: Layer.Layer<
|
|
142
|
+
const static_: Layer.Layer<RenderContext | CurrentEnvironment> = buildWithCurrentEnvironment("static")
|
|
143
143
|
|
|
144
144
|
export {
|
|
145
145
|
/**
|
|
@@ -151,7 +151,7 @@ export {
|
|
|
151
151
|
class RenderQueueImpl implements RenderQueue {
|
|
152
152
|
queue = new Map<unknown, () => void>()
|
|
153
153
|
scheduled = false
|
|
154
|
-
run: Effect.Effect<
|
|
154
|
+
run: Effect.Effect<void, never, Scope.Scope>
|
|
155
155
|
|
|
156
156
|
constructor(
|
|
157
157
|
readonly scope: Scope.Scope,
|
|
@@ -196,7 +196,7 @@ class RenderQueueImpl implements RenderQueue {
|
|
|
196
196
|
)
|
|
197
197
|
})
|
|
198
198
|
|
|
199
|
-
runIdle: Effect.Effect<
|
|
199
|
+
runIdle: Effect.Effect<void, never, Scope.Scope> = Effect.suspend(() => {
|
|
200
200
|
return Effect.flatMap(
|
|
201
201
|
Idle.whenIdle(this.options),
|
|
202
202
|
(deadline) =>
|
|
@@ -219,8 +219,8 @@ class RenderQueueImpl implements RenderQueue {
|
|
|
219
219
|
)
|
|
220
220
|
})
|
|
221
221
|
|
|
222
|
-
runAnimationFrame: Effect.Effect<
|
|
223
|
-
Effect.asyncOption<
|
|
222
|
+
runAnimationFrame: Effect.Effect<void, never, Scope.Scope> = Effect.zipRight(
|
|
223
|
+
Effect.asyncOption<void>((cb) => {
|
|
224
224
|
const id = requestAnimationFrame(() => cb(Effect.unit))
|
|
225
225
|
return Option.some(Effect.sync(() => cancelAnimationFrame(id)))
|
|
226
226
|
}),
|
package/src/Renderable.ts
CHANGED
|
@@ -15,7 +15,7 @@ export type Renderable<R = never, E = never> =
|
|
|
15
15
|
| Placeholder<R, E, any>
|
|
16
16
|
| { readonly [key: string]: Renderable<R, E> | Placeholder<R, E, any> | unknown } // TODO: Should we manage data attributes this way?
|
|
17
17
|
| Placeholder<R, E, any>
|
|
18
|
-
| Effect<
|
|
18
|
+
| Effect<any, E, R>
|
|
19
19
|
| Fx<R, E, any>
|
|
20
20
|
| ReadonlyArray<Renderable<R, E>>
|
|
21
21
|
|
package/src/Test.ts
CHANGED
|
@@ -44,11 +44,11 @@ export interface TestRender<E> {
|
|
|
44
44
|
readonly elementRef: ElementRef.ElementRef
|
|
45
45
|
readonly errors: RefSubject.Computed<never, never, ReadonlyArray<E>>
|
|
46
46
|
readonly lastError: RefSubject.Filtered<never, never, E>
|
|
47
|
-
readonly interrupt: Effect.Effect<
|
|
47
|
+
readonly interrupt: Effect.Effect<void>
|
|
48
48
|
readonly makeEvent: (type: string, eventInitDict?: EventInit) => Event
|
|
49
49
|
readonly makeCustomEvent: <A>(type: string, eventInitDict?: CustomEventInit<A>) => CustomEvent<A>
|
|
50
|
-
readonly dispatchEvent: (options: EventOptions) => Effect.Effect<
|
|
51
|
-
readonly click: (options?: Omit<EventOptions, "event">) => Effect.Effect<
|
|
50
|
+
readonly dispatchEvent: (options: EventOptions) => Effect.Effect<void, Cause.NoSuchElementException>
|
|
51
|
+
readonly click: (options?: Omit<EventOptions, "event">) => Effect.Effect<void, Cause.NoSuchElementException>
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
/**
|
|
@@ -60,9 +60,9 @@ export function testRender<R, E>(
|
|
|
60
60
|
& HappyDOMOptions
|
|
61
61
|
& { readonly [K in keyof DomServicesElementParams]?: (document: Document) => DomServicesElementParams[K] }
|
|
62
62
|
): Effect.Effect<
|
|
63
|
-
|
|
63
|
+
TestRender<E>,
|
|
64
64
|
never,
|
|
65
|
-
|
|
65
|
+
Scope.Scope | Exclude<Exclude<R, RenderTemplate>, RenderContext.RenderContext | CurrentEnvironment | DomServices>
|
|
66
66
|
> {
|
|
67
67
|
return Effect.gen(function*(_) {
|
|
68
68
|
const window = yield* _(getOrMakeWindow(options))
|
|
@@ -155,7 +155,7 @@ export function click<E>(
|
|
|
155
155
|
|
|
156
156
|
function getOrMakeWindow(
|
|
157
157
|
options?: HappyDOMOptions
|
|
158
|
-
): Effect.Effect<
|
|
158
|
+
): Effect.Effect<Window & GlobalThis, never, Scope.Scope> {
|
|
159
159
|
if (typeof window !== "undefined" && typeof document !== "undefined") {
|
|
160
160
|
return Effect.gen(function*(_) {
|
|
161
161
|
window.document.head.innerHTML = ""
|
package/src/Vitest.ts
CHANGED
|
@@ -24,7 +24,7 @@ export {
|
|
|
24
24
|
*/
|
|
25
25
|
export function it<E, A>(
|
|
26
26
|
name: string,
|
|
27
|
-
test: () => Effect.Effect<
|
|
27
|
+
test: () => Effect.Effect<A, E, Scope>,
|
|
28
28
|
options?: vitest.TestOptions
|
|
29
29
|
) {
|
|
30
30
|
return vitest.it(
|
|
@@ -45,7 +45,7 @@ export function test<E, A>(
|
|
|
45
45
|
name: string,
|
|
46
46
|
test: (options: {
|
|
47
47
|
readonly clock: TestClock.TestClock
|
|
48
|
-
}) => Effect.Effect<Scope | TestServices.TestServices
|
|
48
|
+
}) => Effect.Effect<A, E, Scope | TestServices.TestServices>,
|
|
49
49
|
options?: vitest.TestOptions
|
|
50
50
|
) {
|
|
51
51
|
return vitest.it(
|
|
@@ -16,11 +16,11 @@ export interface EventSource {
|
|
|
16
16
|
handler: Handler<Ev>
|
|
17
17
|
) => void
|
|
18
18
|
|
|
19
|
-
readonly setup: (rendered: Rendered, scope: Scope.Scope) => Effect.Effect<
|
|
19
|
+
readonly setup: (rendered: Rendered, scope: Scope.Scope) => Effect.Effect<void>
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
type Entry = readonly [Element, Handler<any>]
|
|
23
|
-
type Run = <E, A>(effect: Effect.Effect<
|
|
23
|
+
type Run = <E, A>(effect: Effect.Effect<A, E>) => Fiber.RuntimeFiber<A, E>
|
|
24
24
|
|
|
25
25
|
const disposable = (f: () => void): Disposable => ({
|
|
26
26
|
[Symbol.dispose]: f
|
|
@@ -130,7 +130,7 @@ export function makeEventSource(): EventSource {
|
|
|
130
130
|
const disposables: Array<Disposable> = []
|
|
131
131
|
const fibers = new Map<symbol, Fiber.RuntimeFiber<any, any>>()
|
|
132
132
|
const runFork = Runtime.runFork(runtime)
|
|
133
|
-
const run: Run = <E, A>(effect: Effect.Effect<
|
|
133
|
+
const run: Run = <E, A>(effect: Effect.Effect<A, E>) => {
|
|
134
134
|
const id = Symbol()
|
|
135
135
|
const fiber = runFork(Effect.onExit(effect, () => Effect.sync(() => fibers.delete(id))))
|
|
136
136
|
fibers.set(id, fiber)
|
package/src/internal/hydrate.ts
CHANGED
|
@@ -95,13 +95,13 @@ export const hydrateTemplate: (document: Document, ctx: RenderContext) => Render
|
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
// Connect our interpolated values to our template parts
|
|
98
|
-
const effects: Array<Effect.Effect<Scope.Scope | Placeholder.Context<Values[number]
|
|
98
|
+
const effects: Array<Effect.Effect<void, never, Scope.Scope | Placeholder.Context<Values[number]>>> = []
|
|
99
99
|
for (const [part, path] of template.parts) {
|
|
100
100
|
const eff = renderPart2(part, where, path, ctx)
|
|
101
101
|
if (eff !== null) {
|
|
102
102
|
effects.push(
|
|
103
103
|
...(Array.isArray(eff) ? eff : [eff]) as Array<
|
|
104
|
-
Effect.Effect<Scope.Scope | Placeholder.Context<Values[number]
|
|
104
|
+
Effect.Effect<void, never, Scope.Scope | Placeholder.Context<Values[number]>>
|
|
105
105
|
>
|
|
106
106
|
)
|
|
107
107
|
}
|
|
@@ -3,19 +3,15 @@ import * as Effect from "effect/Effect"
|
|
|
3
3
|
import * as Option from "effect/Option"
|
|
4
4
|
|
|
5
5
|
export type IndexRefCounter = {
|
|
6
|
-
release: (index: number) => Effect.Effect<
|
|
7
|
-
wait: Effect.Effect<
|
|
6
|
+
release: (index: number) => Effect.Effect<void>
|
|
7
|
+
wait: Effect.Effect<void>
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* @internal
|
|
12
12
|
*/
|
|
13
|
-
export function indexRefCounter(expected: number): Effect.Effect<
|
|
14
|
-
|
|
15
|
-
never,
|
|
16
|
-
IndexRefCounter
|
|
17
|
-
> {
|
|
18
|
-
return Effect.map(Deferred.make<never, void>(), (deferred) => {
|
|
13
|
+
export function indexRefCounter(expected: number): Effect.Effect<IndexRefCounter> {
|
|
14
|
+
return Effect.map(Deferred.make<void>(), (deferred) => {
|
|
19
15
|
const done = Deferred.succeed(deferred, undefined)
|
|
20
16
|
const indexes = new Set<number>(Array.from({ length: expected }, (_, i) => i))
|
|
21
17
|
|
|
@@ -37,20 +33,16 @@ export function indexRefCounter(expected: number): Effect.Effect<
|
|
|
37
33
|
}
|
|
38
34
|
|
|
39
35
|
export type IndexRefCounter2 = {
|
|
40
|
-
release: (index: number) => Effect.Effect<
|
|
41
|
-
expect: (count: number) => Effect.Effect<
|
|
42
|
-
wait: Effect.Effect<
|
|
36
|
+
release: (index: number) => Effect.Effect<void>
|
|
37
|
+
expect: (count: number) => Effect.Effect<boolean>
|
|
38
|
+
wait: Effect.Effect<void>
|
|
43
39
|
}
|
|
44
40
|
|
|
45
41
|
/**
|
|
46
42
|
* @internal
|
|
47
43
|
*/
|
|
48
|
-
export function indexRefCounter2(): Effect.Effect<
|
|
49
|
-
|
|
50
|
-
never,
|
|
51
|
-
IndexRefCounter2
|
|
52
|
-
> {
|
|
53
|
-
return Effect.map(Deferred.make<never, void>(), (deferred) => {
|
|
44
|
+
export function indexRefCounter2(): Effect.Effect<IndexRefCounter2> {
|
|
45
|
+
return Effect.map(Deferred.make<void>(), (deferred) => {
|
|
54
46
|
let expected: Option.Option<number> = Option.none<number>()
|
|
55
47
|
const done = Deferred.succeed(deferred, undefined)
|
|
56
48
|
const indexes = new Set<number>()
|
package/src/internal/parts.ts
CHANGED
|
@@ -33,47 +33,46 @@ import { findHoleComment } from "./utils.js"
|
|
|
33
33
|
|
|
34
34
|
const strictEq = Equivalence.strict<any>()
|
|
35
35
|
|
|
36
|
-
const base = <T extends Part["_tag"]>(tag: T) =>
|
|
37
|
-
|
|
38
|
-
readonly _tag: T = tag
|
|
39
|
-
|
|
40
|
-
constructor(
|
|
41
|
-
readonly index: number,
|
|
42
|
-
readonly commit: (
|
|
43
|
-
params: {
|
|
44
|
-
previous: Extract<Part, { readonly _tag: T }>["value"]
|
|
45
|
-
value: Extract<Part, { readonly _tag: T }>["value"]
|
|
46
|
-
part: Extract<Part, { readonly _tag: T }>
|
|
47
|
-
}
|
|
48
|
-
) => Effect.Effect<Scope, never, void>,
|
|
49
|
-
public value: Extract<Part, { readonly _tag: T }>["value"],
|
|
50
|
-
readonly eq: Equivalence.Equivalence<Extract<Part, { readonly _tag: T }>["value"]> = equals
|
|
51
|
-
) {
|
|
52
|
-
this.update = this.update.bind(this)
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
update(input: this["value"]) {
|
|
56
|
-
const previous = this.value as any
|
|
57
|
-
const value = this.getValue(input) as any
|
|
36
|
+
const base = <T extends Part["_tag"]>(tag: T) => (class Base {
|
|
37
|
+
readonly _tag: T = tag
|
|
58
38
|
|
|
59
|
-
|
|
60
|
-
|
|
39
|
+
constructor(
|
|
40
|
+
readonly index: number,
|
|
41
|
+
readonly commit: (
|
|
42
|
+
params: {
|
|
43
|
+
previous: Extract<Part, { readonly _tag: T }>["value"]
|
|
44
|
+
value: Extract<Part, { readonly _tag: T }>["value"]
|
|
45
|
+
part: Extract<Part, { readonly _tag: T }>
|
|
61
46
|
}
|
|
47
|
+
) => Effect.Effect<void, never, Scope>,
|
|
48
|
+
public value: Extract<Part, { readonly _tag: T }>["value"],
|
|
49
|
+
readonly eq: Equivalence.Equivalence<Extract<Part, { readonly _tag: T }>["value"]> = equals
|
|
50
|
+
) {
|
|
51
|
+
this.update = this.update.bind(this)
|
|
52
|
+
}
|
|
62
53
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
value,
|
|
67
|
-
part: this as any
|
|
68
|
-
}),
|
|
69
|
-
() => Effect.sync(() => this.value = value)
|
|
70
|
-
)
|
|
71
|
-
}
|
|
54
|
+
update(input: this["value"]) {
|
|
55
|
+
const previous = this.value as any
|
|
56
|
+
const value = this.getValue(input) as any
|
|
72
57
|
|
|
73
|
-
|
|
74
|
-
return
|
|
58
|
+
if (this.eq(previous as any, value as any)) {
|
|
59
|
+
return Effect.unit
|
|
75
60
|
}
|
|
61
|
+
|
|
62
|
+
return Effect.flatMap(
|
|
63
|
+
this.commit.call(this, {
|
|
64
|
+
previous,
|
|
65
|
+
value,
|
|
66
|
+
part: this as any
|
|
67
|
+
}),
|
|
68
|
+
() => Effect.sync(() => this.value = value)
|
|
69
|
+
)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
getValue(value: unknown) {
|
|
73
|
+
return value
|
|
76
74
|
}
|
|
75
|
+
})
|
|
77
76
|
|
|
78
77
|
export class AttributePartImpl extends base("attribute") implements AttributePart {
|
|
79
78
|
constructor(
|
|
@@ -295,7 +294,7 @@ export class EventPartImpl implements EventPart {
|
|
|
295
294
|
readonly name: string,
|
|
296
295
|
readonly index: number,
|
|
297
296
|
readonly source: ElementSource<any>,
|
|
298
|
-
readonly onCause: <E>(cause: Cause<E>) => Effect.Effect<
|
|
297
|
+
readonly onCause: <E>(cause: Cause<E>) => Effect.Effect<unknown>,
|
|
299
298
|
readonly addEventListener: <Ev extends Event>(handler: EventHandler<never, never, Ev>) => void
|
|
300
299
|
) {
|
|
301
300
|
}
|
|
@@ -489,35 +488,34 @@ function fromKeyValue(name: string, value: unknown): Array<NameValue> {
|
|
|
489
488
|
}
|
|
490
489
|
}
|
|
491
490
|
|
|
492
|
-
const sparse = <T extends SparsePart["_tag"]>(tag: T) =>
|
|
493
|
-
|
|
494
|
-
readonly _tag: T = tag
|
|
495
|
-
|
|
496
|
-
constructor(
|
|
497
|
-
readonly commit: (
|
|
498
|
-
params: {
|
|
499
|
-
previous: SparseAttributeValues<Extract<SparsePart, { readonly _tag: T }>["parts"]>
|
|
500
|
-
value: SparseAttributeValues<Extract<SparsePart, { readonly _tag: T }>["parts"]>
|
|
501
|
-
part: Extract<SparsePart, { readonly _tag: T }>
|
|
502
|
-
}
|
|
503
|
-
) => Effect.Effect<Scope, never, void>,
|
|
504
|
-
public value: SparseAttributeValues<Extract<SparsePart, { readonly _tag: T }>["parts"]>,
|
|
505
|
-
readonly eq: Equivalence.Equivalence<SparseAttributeValues<Extract<SparsePart, { readonly _tag: T }>["parts"]>> =
|
|
506
|
-
equals
|
|
507
|
-
) {}
|
|
508
|
-
|
|
509
|
-
update = (value: this["value"]) => {
|
|
510
|
-
if (this.eq(this.value as any, value as any)) {
|
|
511
|
-
return Effect.unit
|
|
512
|
-
}
|
|
491
|
+
const sparse = <T extends SparsePart["_tag"]>(tag: T) => (class Base {
|
|
492
|
+
readonly _tag: T = tag
|
|
513
493
|
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
494
|
+
constructor(
|
|
495
|
+
readonly commit: (
|
|
496
|
+
params: {
|
|
497
|
+
previous: SparseAttributeValues<Extract<SparsePart, { readonly _tag: T }>["parts"]>
|
|
498
|
+
value: SparseAttributeValues<Extract<SparsePart, { readonly _tag: T }>["parts"]>
|
|
499
|
+
part: Extract<SparsePart, { readonly _tag: T }>
|
|
500
|
+
}
|
|
501
|
+
) => Effect.Effect<void, never, Scope>,
|
|
502
|
+
public value: SparseAttributeValues<Extract<SparsePart, { readonly _tag: T }>["parts"]>,
|
|
503
|
+
readonly eq: Equivalence.Equivalence<SparseAttributeValues<Extract<SparsePart, { readonly _tag: T }>["parts"]>> =
|
|
504
|
+
equals
|
|
505
|
+
) {}
|
|
506
|
+
|
|
507
|
+
update = (value: this["value"]) => {
|
|
508
|
+
if (this.eq(this.value as any, value as any)) {
|
|
509
|
+
return Effect.unit
|
|
519
510
|
}
|
|
511
|
+
|
|
512
|
+
return this.commit({
|
|
513
|
+
previous: this.value,
|
|
514
|
+
value: this.value = value as any,
|
|
515
|
+
part: this
|
|
516
|
+
} as any)
|
|
520
517
|
}
|
|
518
|
+
})
|
|
521
519
|
|
|
522
520
|
type SparseAttributeValues<T extends ReadonlyArray<AttributePart | ClassNamePart | CommentPart | StaticText>> =
|
|
523
521
|
ReadonlyArray<
|
package/src/internal/render.ts
CHANGED
|
@@ -55,7 +55,7 @@ export type RenderPartContext = {
|
|
|
55
55
|
readonly refCounter: IndexRefCounter2
|
|
56
56
|
readonly renderContext: RenderContext
|
|
57
57
|
readonly values: ReadonlyArray<Renderable<any, any>>
|
|
58
|
-
readonly onCause: (cause: Cause<any>) => Effect.Effect<
|
|
58
|
+
readonly onCause: (cause: Cause<any>) => Effect.Effect<void>
|
|
59
59
|
|
|
60
60
|
readonly makeHydrateContext?: (index: number) => HydrateContext
|
|
61
61
|
|
|
@@ -68,7 +68,7 @@ type RenderPartMap = {
|
|
|
68
68
|
part: Extract<Template.PartNode | Template.SparsePartNode, { _tag: K }>,
|
|
69
69
|
node: Node,
|
|
70
70
|
ctx: RenderPartContext
|
|
71
|
-
) => null | Effect.Effect<
|
|
71
|
+
) => null | Effect.Effect<void, any, any> | Array<Effect.Effect<void, any, any>>
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
const RenderPartMap: RenderPartMap = {
|
|
@@ -283,7 +283,7 @@ const RenderPartMap: RenderPartMap = {
|
|
|
283
283
|
added.forEach((a) => previous.add(a))
|
|
284
284
|
}
|
|
285
285
|
|
|
286
|
-
const effects: Array<Effect.Effect<
|
|
286
|
+
const effects: Array<Effect.Effect<void, any, any>> = []
|
|
287
287
|
const entries = Object.entries(renderable)
|
|
288
288
|
|
|
289
289
|
loop:
|
|
@@ -403,7 +403,7 @@ const RenderPartMap: RenderPartMap = {
|
|
|
403
403
|
return ctx.renderContext.queue.add(element, () => attr.value = values.join(""))
|
|
404
404
|
})
|
|
405
405
|
|
|
406
|
-
const effects: Array<Effect.Effect<
|
|
406
|
+
const effects: Array<Effect.Effect<void, any, any>> = []
|
|
407
407
|
|
|
408
408
|
for (let i = 0; i < templatePart.nodes.length; ++i) {
|
|
409
409
|
const node = templatePart.nodes[i]
|
|
@@ -420,7 +420,7 @@ const RenderPartMap: RenderPartMap = {
|
|
|
420
420
|
templatePart.name,
|
|
421
421
|
node.index,
|
|
422
422
|
({ value }) => setValue(value, index),
|
|
423
|
-
|
|
423
|
+
attr.value
|
|
424
424
|
),
|
|
425
425
|
(f) => Effect.zipRight(ctx.renderContext.queue.add(element, f), ctx.refCounter.release(node.index)),
|
|
426
426
|
() => ctx.expected++
|
|
@@ -461,7 +461,7 @@ const RenderPartMap: RenderPartMap = {
|
|
|
461
461
|
return ctx.renderContext.queue.add(comment, () => comment.textContent = values.join(""))
|
|
462
462
|
})
|
|
463
463
|
|
|
464
|
-
const effects: Array<Effect.Effect<
|
|
464
|
+
const effects: Array<Effect.Effect<void, any, any>> = []
|
|
465
465
|
|
|
466
466
|
for (let i = 0; i < templatePart.nodes.length; ++i) {
|
|
467
467
|
const node = templatePart.nodes[i]
|
|
@@ -551,7 +551,7 @@ export function renderPart2(
|
|
|
551
551
|
content: ParentChildNodes,
|
|
552
552
|
path: Chunk<number>,
|
|
553
553
|
ctx: RenderPartContext
|
|
554
|
-
): Effect.Effect<
|
|
554
|
+
): Effect.Effect<void, any, any> | Array<Effect.Effect<void, any, any>> | null {
|
|
555
555
|
return RenderPartMap[part._tag](part as any, findPath(content, path), ctx)
|
|
556
556
|
}
|
|
557
557
|
|
|
@@ -592,13 +592,13 @@ export const renderTemplate: (document: Document, renderContext: RenderContext)
|
|
|
592
592
|
}
|
|
593
593
|
|
|
594
594
|
// Connect our interpolated values to our template parts
|
|
595
|
-
const effects: Array<Effect.Effect<Scope.Scope | Placeholder.Context<Values[number]
|
|
595
|
+
const effects: Array<Effect.Effect<void, never, Scope.Scope | Placeholder.Context<Values[number]>>> = []
|
|
596
596
|
for (const [part, path] of entry.template.parts) {
|
|
597
597
|
const eff = renderPart2(part, content, path, ctx)
|
|
598
598
|
if (eff !== null) {
|
|
599
599
|
effects.push(
|
|
600
600
|
...(Array.isArray(eff) ? eff : [eff]) as Array<
|
|
601
|
-
Effect.Effect<Scope.Scope | Placeholder.Context<Values[number]
|
|
601
|
+
Effect.Effect<void, never, Scope.Scope | Placeholder.Context<Values[number]>>
|
|
602
602
|
>
|
|
603
603
|
)
|
|
604
604
|
}
|
|
@@ -643,7 +643,7 @@ export const renderTemplate: (document: Document, renderContext: RenderContext)
|
|
|
643
643
|
function getEventHandler<R, E>(
|
|
644
644
|
renderable: any,
|
|
645
645
|
ctx: Context.Context<any> | Context.Context<never>,
|
|
646
|
-
onCause: (cause: Cause<E>) => Effect.Effect<
|
|
646
|
+
onCause: (cause: Cause<E>) => Effect.Effect<unknown>
|
|
647
647
|
): EventHandler.EventHandler<never, never> | null {
|
|
648
648
|
if (renderable && typeof renderable === "object") {
|
|
649
649
|
if (EventHandler.EventHandlerTypeId in renderable) {
|
|
@@ -666,7 +666,7 @@ function getEventHandler<R, E>(
|
|
|
666
666
|
function handlePart<R, E, R2>(
|
|
667
667
|
renderable: unknown,
|
|
668
668
|
sink: Sink.Sink<R2, any, any>
|
|
669
|
-
): Effect.Effect<R | R2 | Scope.Scope
|
|
669
|
+
): Effect.Effect<any, never, R | R2 | Scope.Scope> {
|
|
670
670
|
switch (typeof renderable) {
|
|
671
671
|
case "undefined":
|
|
672
672
|
case "object": {
|
|
@@ -678,7 +678,7 @@ function handlePart<R, E, R2>(
|
|
|
678
678
|
} else if (TypeId in renderable) {
|
|
679
679
|
return (renderable as Fx.Fx<R | R2, any, any>).run(sink)
|
|
680
680
|
} else if (Effect.EffectTypeId in renderable) {
|
|
681
|
-
return Effect.matchCauseEffect(renderable as Effect.Effect<
|
|
681
|
+
return Effect.matchCauseEffect(renderable as Effect.Effect<any, E, R>, sink)
|
|
682
682
|
} else return sink.onSuccess(renderable)
|
|
683
683
|
}
|
|
684
684
|
default:
|
|
@@ -710,7 +710,7 @@ export function attachRoot<T extends RenderEvent | null>(
|
|
|
710
710
|
cache: RenderContext["renderCache"],
|
|
711
711
|
where: HTMLElement,
|
|
712
712
|
what: RenderEvent | null // TODO: Should we support HTML RenderEvents here too?
|
|
713
|
-
): Effect.Effect<
|
|
713
|
+
): Effect.Effect<ToRendered<T>> {
|
|
714
714
|
return Effect.sync(() => {
|
|
715
715
|
const wire = what?.valueOf() as ToRendered<T>
|
|
716
716
|
const previous = cache.get(where)
|
|
@@ -883,7 +883,7 @@ function matchSettablePart(
|
|
|
883
883
|
renderable: Renderable<any, any>,
|
|
884
884
|
setValue: (value: any) => void,
|
|
885
885
|
makePart: () => Part,
|
|
886
|
-
schedule: (f: () => void) => Effect.Effect<
|
|
886
|
+
schedule: (f: () => void) => Effect.Effect<void, never, Scope.Scope>,
|
|
887
887
|
expect: () => void
|
|
888
888
|
) {
|
|
889
889
|
return matchRenderable(renderable, {
|
|
@@ -897,7 +897,8 @@ function matchSettablePart(
|
|
|
897
897
|
},
|
|
898
898
|
Directive: (directive) => {
|
|
899
899
|
expect()
|
|
900
|
-
|
|
900
|
+
const part = makePart()
|
|
901
|
+
return Effect.flatMap(directive(part), () => schedule(() => setValue(part.value)))
|
|
901
902
|
},
|
|
902
903
|
Otherwise: (otherwise) => {
|
|
903
904
|
setValue(otherwise)
|
|
@@ -907,11 +908,11 @@ function matchSettablePart(
|
|
|
907
908
|
}
|
|
908
909
|
|
|
909
910
|
function matchRenderable(renderable: Renderable<any, any>, matches: {
|
|
910
|
-
Fx: (fx: Fx.Fx<any, any, any>) => Effect.Effect<
|
|
911
|
-
Effect: (effect: Effect.Effect<any, any, any>) => Effect.Effect<
|
|
912
|
-
Directive: (directive: Directive<any, any>) => Effect.Effect<
|
|
913
|
-
Otherwise: (_: Renderable<any, any>) => Effect.Effect<
|
|
914
|
-
}): Effect.Effect<
|
|
911
|
+
Fx: (fx: Fx.Fx<any, any, any>) => Effect.Effect<void, any, any> | null
|
|
912
|
+
Effect: (effect: Effect.Effect<any, any, any>) => Effect.Effect<void, any, any> | null
|
|
913
|
+
Directive: (directive: Directive<any, any>) => Effect.Effect<void, any, any> | null
|
|
914
|
+
Otherwise: (_: Renderable<any, any>) => Effect.Effect<void, any, any> | null
|
|
915
|
+
}): Effect.Effect<void, any, any> | null {
|
|
915
916
|
if (Fx.isFx(renderable)) {
|
|
916
917
|
return matches.Fx(renderable)
|
|
917
918
|
} else if (Effect.isEffect(renderable)) {
|
package/src/internal/server.ts
CHANGED
|
@@ -70,7 +70,7 @@ type RenderChunkMap = {
|
|
|
70
70
|
chunk: Extract<HtmlChunk, { _tag: K }>,
|
|
71
71
|
index: number,
|
|
72
72
|
values: ReadonlyArray<Renderable<any, any>>,
|
|
73
|
-
onChunk: (index: number, value: string) => Effect.Effect<
|
|
73
|
+
onChunk: (index: number, value: string) => Effect.Effect<void>
|
|
74
74
|
) => RenderChunk<R, E>
|
|
75
75
|
}
|
|
76
76
|
|
|
@@ -98,7 +98,7 @@ const renderChunkMap: RenderChunkMap = {
|
|
|
98
98
|
export function htmlChunksToRenderChunks<R, E>(
|
|
99
99
|
chunks: ReadonlyArray<HtmlChunk>,
|
|
100
100
|
values: ReadonlyArray<Renderable<R, E>>,
|
|
101
|
-
onChunk: (index: number, value: string) => Effect.Effect<
|
|
101
|
+
onChunk: (index: number, value: string) => Effect.Effect<void>
|
|
102
102
|
) {
|
|
103
103
|
const output: Array<RenderChunk<R, E>> = Array(chunks.length)
|
|
104
104
|
|
|
@@ -113,7 +113,7 @@ export function htmlChunksToRenderChunks<R, E>(
|
|
|
113
113
|
type PartNodeMap = {
|
|
114
114
|
readonly [K in PartNode["_tag"]]: (
|
|
115
115
|
node: Extract<PartNode, { _tag: K }>,
|
|
116
|
-
onChunk: (value: unknown) => Effect.Effect<
|
|
116
|
+
onChunk: (value: unknown) => Effect.Effect<void>
|
|
117
117
|
) => Part
|
|
118
118
|
}
|
|
119
119
|
|
|
@@ -137,14 +137,14 @@ const partNodeMap: PartNodeMap = {
|
|
|
137
137
|
|
|
138
138
|
export function partNodeToPart(
|
|
139
139
|
node: PartNode,
|
|
140
|
-
onChunk: (value: unknown) => Effect.Effect<
|
|
140
|
+
onChunk: (value: unknown) => Effect.Effect<void>
|
|
141
141
|
): Part {
|
|
142
142
|
return partNodeMap[node._tag](node as any, onChunk)
|
|
143
143
|
}
|
|
144
144
|
|
|
145
145
|
function sparsePartNodeToPart(
|
|
146
146
|
node: SparsePartNode,
|
|
147
|
-
onChunk: (value: string | null) => Effect.Effect<
|
|
147
|
+
onChunk: (value: string | null) => Effect.Effect<void>
|
|
148
148
|
) {
|
|
149
149
|
if (node._tag === "sparse-attr") {
|
|
150
150
|
return renderSparseAttr(node, onChunk)
|
|
@@ -157,7 +157,7 @@ function sparsePartNodeToPart(
|
|
|
157
157
|
|
|
158
158
|
function renderSparseAttr(
|
|
159
159
|
attrNode: SparseAttrNode,
|
|
160
|
-
setAttribute: (value: string | null) => Effect.Effect<
|
|
160
|
+
setAttribute: (value: string | null) => Effect.Effect<void>
|
|
161
161
|
): SparseAttributePart {
|
|
162
162
|
const { nodes } = attrNode
|
|
163
163
|
const values: Map<number, string | null> = new Map()
|
|
@@ -204,7 +204,7 @@ function renderSparseAttr(
|
|
|
204
204
|
|
|
205
205
|
function renderSparseClassName(
|
|
206
206
|
classNameNode: SparseClassNameNode,
|
|
207
|
-
setClassName: (value: string | null) => Effect.Effect<
|
|
207
|
+
setClassName: (value: string | null) => Effect.Effect<void>
|
|
208
208
|
): SparseClassNamePart {
|
|
209
209
|
const { nodes } = classNameNode
|
|
210
210
|
const values: Map<number, string | null> = new Map()
|
|
@@ -250,7 +250,7 @@ function renderSparseClassName(
|
|
|
250
250
|
|
|
251
251
|
function renderSparseComment(
|
|
252
252
|
commentNode: SparseCommentNode,
|
|
253
|
-
setComment: (value: string | null) => Effect.Effect<
|
|
253
|
+
setComment: (value: string | null) => Effect.Effect<void>
|
|
254
254
|
): SparseCommentPart {
|
|
255
255
|
const { nodes } = commentNode
|
|
256
256
|
const values: Map<number, string | null | undefined> = new Map()
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.TemplateInstance = TemplateInstance;
|
|
7
|
-
exports.TemplateInstanceTypeId = void 0;
|
|
8
|
-
var _Fx = /*#__PURE__*/require("@typed/fx/Fx");
|
|
9
|
-
var _ElementRef = /*#__PURE__*/require("./ElementRef.js");
|
|
10
|
-
/**
|
|
11
|
-
* @since 1.0.0
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* @since 1.0.0
|
|
16
|
-
*/
|
|
17
|
-
const TemplateInstanceTypeId = exports.TemplateInstanceTypeId = /*#__PURE__*/Symbol.for("@typed/template/TemplateInstance");
|
|
18
|
-
/**
|
|
19
|
-
* @since 1.0.0
|
|
20
|
-
*/
|
|
21
|
-
function TemplateInstance(events, ref) {
|
|
22
|
-
return new TemplateInstanceImpl(events, ref);
|
|
23
|
-
}
|
|
24
|
-
// @ts-expect-error does not implement Placeholder
|
|
25
|
-
class TemplateInstanceImpl extends _Fx.FxEffectBase {
|
|
26
|
-
i0;
|
|
27
|
-
i1;
|
|
28
|
-
[TemplateInstanceTypeId] = TemplateInstanceTypeId;
|
|
29
|
-
query;
|
|
30
|
-
events;
|
|
31
|
-
elements;
|
|
32
|
-
dispatchEvent;
|
|
33
|
-
version;
|
|
34
|
-
constructor(i0, i1) {
|
|
35
|
-
super();
|
|
36
|
-
this.i0 = i0;
|
|
37
|
-
this.i1 = i1;
|
|
38
|
-
this.query = this.i1.query;
|
|
39
|
-
this.events = this.i1.events;
|
|
40
|
-
this.elements = this.i1.elements;
|
|
41
|
-
this.dispatchEvent = this.i1.dispatchEvent;
|
|
42
|
-
this.version = this.i1[_ElementRef.ElementRefTypeId].version;
|
|
43
|
-
}
|
|
44
|
-
toFx() {
|
|
45
|
-
return this.i0;
|
|
46
|
-
}
|
|
47
|
-
toEffect() {
|
|
48
|
-
return this.i1;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
//# sourceMappingURL=TemplateInstance.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TemplateInstance.js","names":["_Fx","require","_ElementRef","TemplateInstanceTypeId","exports","Symbol","for","TemplateInstance","events","ref","TemplateInstanceImpl","FxEffectBase","i0","i1","query","elements","dispatchEvent","version","constructor","ElementRefTypeId","toFx","toEffect"],"sources":["../../src/TemplateInstance.ts"],"sourcesContent":[null],"mappings":";;;;;;;AAKA,IAAAA,GAAA,gBAAAC,OAAA;AAMA,IAAAC,WAAA,gBAAAD,OAAA;AAXA;;;;AAcA;;;AAGO,MAAME,sBAAsB,GAAAC,OAAA,CAAAD,sBAAA,gBAAGE,MAAM,CAACC,GAAG,CAAC,kCAAkC,CAAC;AAuBpF;;;AAGM,SAAUC,gBAAgBA,CAC9BC,MAAoC,EACpCC,GAAkB;EAElB,OAAO,IAAIC,oBAAoB,CAACF,MAAM,EAAEC,GAAG,CAAQ;AACrD;AAEA;AACA,MAAMC,oBACJ,SAAQC,gBAAyE;EAWtEC,EAAA;EACAC,EAAA;EATF,CAACV,sBAAsB,IAA4BA,sBAAsB;EAClFW,KAAK;EACLN,MAAM;EACNO,QAAQ;EACRC,aAAa;EACbC,OAAO;EAEPC,YACWN,EAAgC,EAChCC,EAAiB;IAE1B,KAAK,EAAE;IAHE,KAAAD,EAAE,GAAFA,EAAE;IACF,KAAAC,EAAE,GAAFA,EAAE;IAIX,IAAI,CAACC,KAAK,GAAG,IAAI,CAACD,EAAE,CAACC,KAAK;IAC1B,IAAI,CAACN,MAAM,GAAG,IAAI,CAACK,EAAE,CAACL,MAAM;IAC5B,IAAI,CAACO,QAAQ,GAAG,IAAI,CAACF,EAAE,CAACE,QAAQ;IAChC,IAAI,CAACC,aAAa,GAAG,IAAI,CAACH,EAAE,CAACG,aAAa;IAC1C,IAAI,CAACC,OAAO,GAAG,IAAI,CAACJ,EAAE,CAACM,4BAAgB,CAAC,CAACF,OAAO;EAClD;EAEAG,IAAIA,CAAA;IACF,OAAO,IAAI,CAACR,EAAE;EAChB;EAEAS,QAAQA,CAAA;IACN,OAAO,IAAI,CAACR,EAAE;EAChB"}
|