T
TyphonJSgeoidesic

Update to ChatMessage outside of Svelte doesn't trigger reactivity on linked TJSDocument

I'm a bit confused about this... 1. When I render a ChatMessage via svelte, in the chat message svelte component I do:
let foundryChatMessageDocument = new TJSDocument(void 0, { delete: () => {} }),

onMount(async () => {
await foundryChatMessageDocument.set(await game.messages.get(messageId));
let foundryChatMessageDocument = new TJSDocument(void 0, { delete: () => {} }),

onMount(async () => {
await foundryChatMessageDocument.set(await game.messages.get(messageId));
2. At various points in the workflow I save updates to the chat message using:
await $foundryChatMessageDocument.update({
flags: {
surge: { data: { contest: contestsData } },
},
});
await $foundryChatMessageDocument.update({
flags: {
surge: { data: { contest: contestsData } },
},
});
Which works reactivly. 3. However, I then have a class, which is not a svelte component because it represents shared logic. In that class I also update the chat message like so:
const message = game.messages.get(messageId);
message.update({ flags: { surge: { data: { contest } } } })
const message = game.messages.get(messageId);
message.update({ flags: { surge: { data: { contest } } } })
These changes are not however picked up within foundryChatMessageDocument reactively. I assume that is expected. However, is there a way I can make the update to the chat message in point 3 be reactively picked up by the TJSDocument?
TM
TyphonJS (Michael)306d ago
Do you have a reactive statement in your component? $: if ($foundryChatMessageDocument) { // do something. } https://svelte.dev/tutorial/reactive-statements Also do keep in mind that changing a document with the sample code that I provided is not going to work well w/ Svelte. The core ChatLog is going to improperly / not destroy the component correctly; re-render and attach a new one and such. Unless you modify ChatLog.updateMessage you are in for a world of confusion and pain.
G
geoidesic306d ago
I have done that last bit, based on your comments in the Svelte server, thx and it did relieve a world of pain indeed! But in principle here, should I expect $foundryChatMessageDocument to react to all updates to the Chat Message, even if not done via $foundryChatMessageDocument.update() but rather directly through core foundry?
Do you have a reactive statement in your component?
I have put one in now and it is not triggering after the update from the class.
TM
TyphonJS (Michael)306d ago
It should work, but unfortunately I can't debug your code if you happen to be doing something slightly incorrect. You can certainly step through the TJSDocument code yourself and verify that things are working or not. I gather you are on the latest TRL "alpha" release 0.0.23 I believe or 0.1.0 has the changes required to work on v11. Install essential-svelte-esm and make sure the document examples work there. If they do you are likely doing something wrong. RE: Your feature request: https://discord.com/channels/170995199584108546/517504137403826177/1128115256858775582 You are trying to fit a square peg in a circular opening w/ most of what you are attempting. Constantly updating a chat message for flag data is not recommended. You really should be investigating using sockets to update a chat message with dynamic / changing targeting data and then when it is locked in and executed then you only update a chat message document once if that is necessary at all. IE quite likely that final targeting data is being consumed by some other part of your system to make something else go.
Want results from more Discord servers?
Add your server
More Posts
Release `TRL 0.1.0` - The journey to beta begins...Greets @FVTT ▹ Developer, I am very excited to announce the release of TRL `0.1.0`. This is a majorHow do I get the elementRoot of a ChatMessage?SvelteApplication provides `elementRoot` prop to components that implement it, which is very useful.Getting started with the GUI and understanding element rootIt's been a while, but I've been working on my Knowledge Recalled module since V11 is out, and my frDrag & Drop broke in v11Ok so something that broke for me when moving to v11 is drag&drop from both the items tab of the sidTJSDocument and Token Issues```js const tokens = cardData.targets .map(t => [t, fromUuidSync(t)]) .filter(([_, tSyrinControl & Svelte...I gather there is a bit to discuss... 😄Ver .11Not sure if this is the place to ask, but updated to v .7.11 foundry 10. Lost all quest data. FoldePackage Release: Foundry Summons (3rd party)Greets @everyone. I do try to use pings sparingly, but want to show a spotlight on @vauxs new packagCreating an interim TJSDocument / document attribute bridgeHi @wasp... Just moving discussion here as it is a better forum post. > So I have made a system wiTJSGameSettings with not registered settings.I am not sure what is happening in here. I have created an attachement to the existing Settings pagStoring a collection of Items in an Item?Use cases would be: - containers could contain other Items - some items have prerequisites, which coRelease: Quest Log `0.7.12`Greets @FVTT ▹ Quest Log! The v11 compatibility release is now available from the Foundry package mTJSDialog how to use buttons and callback or return value?I'm planning to use TJSDialog to act as an intervening Application. So... player clicks a button thaRelease: `TRL 0.0.23` - "v11 hot patch"Greets @FVTT ▹ Developer! I just released a hot patch of TRL for v11 support. The only thing changv11 Debug embedded collection changesJust a post to track the v11 changes to embedded collections and what needs to be updated in an inteCopying existing FQL to a new worldHello! I am running a world with Forien's Quest Log set up in a world, and I updated Foundry from v8How can I create an embeddedCollection in a chat message?I have this: ```javascript const messageDocument = game.messages.get(message._id); const doc = new THooks in svelte component? (not really a typhon question but nowhere else to ask :)In my foundry index.js I'm listening for hook: ```javascript Hooks.on('renderChatMessage', doSomethi