add re-render method

This commit is contained in:
MapleLeaf
2021-12-09 03:01:13 -06:00
parent ade2464aaf
commit a7b1221524
2 changed files with 18 additions and 6 deletions

View File

@@ -35,15 +35,24 @@ test("rendering text", async (t) => {
const content = nanoid() const content = nanoid()
const root = render(content, channel) const root = render(content, channel)
await waitForWithTimeout( await waitForWithTimeout(async () => {
() => channel.messages.cache.some((m) => m.content === content), const messages = await channel.messages.fetch()
4000, return messages.some((m) => m.content === content)
) }, 4000)
const newContent = nanoid()
root.rerender(newContent)
await waitForWithTimeout(async () => {
const messages = await channel.messages.fetch({ limit: 1 })
return messages.some((m) => m.content === content)
}, 4000)
root.destroy() root.destroy()
await waitForWithTimeout(() => { await waitForWithTimeout(async () => {
return channel.messages.cache const messages = await channel.messages.fetch({ limit: 1 })
return messages
.filter((m) => !m.deleted) .filter((m) => !m.deleted)
.every((m) => m.content !== content) .every((m) => m.content !== content)
}, 4000) }, 4000)

View File

@@ -10,6 +10,9 @@ export function render(content: string, target: ReacordRenderTarget) {
const containerId = reconciler.createContainer(container, 0, false, null) const containerId = reconciler.createContainer(container, 0, false, null)
reconciler.updateContainer(content, containerId) reconciler.updateContainer(content, containerId)
return { return {
rerender: (newContent: string) => {
reconciler.updateContainer(newContent, containerId)
},
destroy: () => { destroy: () => {
reconciler.updateContainer(null, containerId) reconciler.updateContainer(null, containerId)
}, },