Skip to content

Commit f3a49d7

Browse files
committed
fix: enable init ctx emitter also on promised models
1 parent 00e4fe5 commit f3a49d7

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

packages/core/src/app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,14 @@ class AppImpl<MODEL, MESSAGE> implements App<MODEL, MESSAGE> {
149149
m
150150
.then(model => {
151151
this._model = model
152+
initCtx.enable()
152153
this.performUpdate()
153154
})
154155
.catch(console.error)
155156
return
156157
}
157158

158159
this._model = m
159-
160160
initCtx.enable()
161161
}
162162

packages/core/test/unit/app.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,5 +122,16 @@ describe("app.ts", () => {
122122
await sleep(70)
123123
expect(removeMarkerComments(document.body.innerHTML)).toBe("<p>hello again</p>")
124124
})
125+
126+
it("should emit async messages from model init that returns a promise", async () => {
127+
createApp(({emit}) => {
128+
setTimeout(() => emit("hello again"), 50)
129+
return Promise.resolve("hello, world")
130+
}, update, view).mount(document.body)
131+
await sleep(1)
132+
expect(removeMarkerComments(document.body.innerHTML)).toBe("<p>hello, world</p>")
133+
await sleep(70)
134+
expect(removeMarkerComments(document.body.innerHTML)).toBe("<p>hello again</p>")
135+
})
125136
})
126137
})

0 commit comments

Comments
 (0)