How to update CustomStructureProperty value and have custom theme pick up changes
See original GitHub issueI’m working on trying to inject some dynamic data (i.e. I can’t hardcode it) into a custom theme to use to colour atoms.
The approach I’m try to use is have a CustomStructureProperty and PluginBehavior, update the value in the provider as needed and read it in our custom theme
In a state action I call
StructureColorPropertyProvider.set(
structure,
{ pocket: params.extra.pocket },
params.extra.pocket
);
where params
is some data we get from react props, to set the value
However by this point the theme has already been run once and doesn’t seem to get triggered again (as in the top level function does not run again) I have to call
plugin.dataTransaction(async () => {
for (const s of plugin.managers.structure.hierarchy.current.structures) {
await plugin.managers.structure.component.updateRepresentationsTheme(
s.components,
{ color: CustomThemeProvider.name as any }
);
}
});
to make the theme refresh, which doesn’t seem correct because it’s re-applying the theme to every structure and it couples the behaviour to a single theme. Is there a better way of doing this?
Issue Analytics
- State:
- Created 10 months ago
- Comments:11 (5 by maintainers)
Top Results From Across the Web
Create and update a collection in a canvas app - Microsoft Learn
Press F5, type some text into ProductName, select an option in Colors, and then select Add. Repeat the previous step at least two...
Read more >A Complete Guide to Custom Properties | CSS-Tricks
Custom properties are surprisingly tolerant when it comes to the values they accept. Here are some basic examples that you'd expect to work,...
Read more >Global Settings & Styles (theme.json) | Block Editor Handbook
By using the theme.json file to set style properties in a structured way, the Block Editor can “manage” the CSS that comes from...
Read more >Theme settings - Shopify Help Center
From your Shopify admin, go to Online Store > Themes. Find the theme that you want to edit, and then click Customize.
Read more >How to Edit, Customize, and Override Bootstrap CSS to Suit ...
You simply have to copy and paste the variables in your custom.scss file, change their values, and delete the !default flag. So if...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The state tree was designed around the idea that the information needed is contained in the props of a node and it uses react-like state reconciliation to update what is rendered. That is why you need to pass the dummy prop.
What you were/are doing with your approach would be analogous to assigning the value returned by useState in react and expecting the component to re-render.
Right, sorry. You can try passing the existing params (
selector.cell?.transform.params
), or use an empty callback.update(x => {})
.Also, the preset itself might be an overkill for your use case and you might just include the model/structure creation, assign the custom prop, and then create your representation.