T
TyphonJS15mo ago
Vauxs

Creating a svelte store of a document's flags

Is this wise, if even possible? Like I want to create a writable store of a message's flags, so that I can freely edit it without having to worry about Foundry's update functions.
11 Replies
Vauxs
Vauxs15mo ago
Checking Custom Stores, I suppose an easier way would be to create a custom store with an update function embedded into it. https://svelte.dev/tutorial/custom-stores
TyphonJS (Michael)
This will be addressed in the near future with the 2nd half of TJSDocument support where it will be possible to create automatic stores from document field paths including flags. They'll update the backing document correctly behind the scene and update when new data arrives. I'll be investigating a potential fork of this Svelte add on store library to provide some implementation aspects to the process. Just note that this library itself is not the solution as it needs to be modified according to the Foundry document model process. https://github.com/bryanmylee/svelte-keyed Upcoming major features I'll be working on: - Implement the drag and drop / automatic sorting of reactive embedded collections. - 2nd half of TJSDocument overhaul for individual store / property creation. With any luck I'll have both of these completed later this month.
Vauxs
Vauxs15mo ago
oh that will be lovely especially with me failing to make such a custom store, at least for now
TyphonJS (Michael)
It can be tricky. There are several examples and even really involved custom stores in TRL. For example the customized Position system that replaces the core Foundry handling of positional aspects for apps is super involved and has a lot of code. Position.js, but a lot of code in this folder. https://github.com/typhonjs-fvtt-lib/svelte/tree/main/src/application/position I imagine that the code involved for custom document stores via TJSDocument will look similar to svelte-keyed, but certainly be different enough.
Vauxs
Vauxs15mo ago
Got it working 😄 even works with auto-subscribe $ key which is lovely
TyphonJS (Michael)
Very nice. It shouldn't be too bad. Got a link to check out what you came up with?
Vauxs
Vauxs15mo ago
Probably haphazard for what it's worth Already experiencing that haphazardness, as usual.
TyphonJS (Michael)
It is a bit haphazard. get targets and updateMessage looks suspect. Anytime you run subscribe it returns an unsubscribe function and I see usage of subscribe for access to the data stored in the writable. There is a get function from svelte/store that can be handy, but probably what makes most sense is storing the target array in a local private variable so that you can always have access to it. It also looks like this is a one way store insofar that there is no hookup to the _message / document to receive changes from the server.
Vauxs
Vauxs15mo ago
Definitely not counting on anything coming from the other side. It's just for the flag for my module only.
TyphonJS (Michael)
It could be worth looking at TJSDocument for ideas particularly around subscribing to the Foundry document by "faking" the close / render method of an Application. close gets called when a document is deleted. Render is invoked with a context object that gives some idea on what CRUD operation is occurring. https://github.com/typhonjs-fvtt-lib/svelte/blob/main/src/store/document/TJSDocument.js Another general improvement is just implementing the store contract directly and not using writable. A good article on that: https://monad.fi/en/blog/svelte-custom-stores/ Most of the custom stores I create don't involve writable. This gives you a bit of extra flexibility in having direct access to the data vs less elegant ways of accessing it like you are doing presently.
Want results from more Discord servers?
Add your server
More Posts
Dropdowns are not mouse-interactable inside ApplicationShellI can't click on the entries created by either Svelecte or svelte-select if that dropdown is inside Welcome to our Foundry VTT package discussion forum!Hello fellow Foundry VTT enthusiasts. This forum channel is for discussing and asking questions abouChat Message Failed to RenderAttempting to load multiple svelte elements into a chat message. So far I was successful, but the moSettings are not a store and Chat Messages TalkI wanted to grab the `TJSGameSettings` stores, but it seems that they are not actual stores? They haSettings PageI was looking at ways to override the default foundry tab for settings and was wondering if there's Release: `svelte-standard` 0.0.23 - "secrets" in editor components respect GM user level.Greets @FVTT ▹ Developer! Just a small patch note for `svelte-standard` that went out earlier thisRelease: `svelte-standard` 0.0.22 - small fix for new a11y warnings in latest Svelte.Greets @FVTT ▹ Developer. I just pushed out a small update to `svelte-standard` to handle the new a1Core chat sidebar extensionContinuing a discussion with @voodoofrog about a project to extend the core chat sidebar panel.Release: `svelte-standard` 0.0.21 - Svelte sidebar apps refinement (final?)Greets @FVTT ▹ Developer. This update provides what should be the final refinement for `FVTTSidebarCSequencer: Powered by SvelteI've started on the long overdue conversion for sequencer to have its UI powered by Svelte, which al