question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to update CustomStructureProperty value and have custom theme pick up changes

See original GitHub issue

I’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:closed
  • Created 10 months ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
dsehnalcommented, Nov 16, 2022

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.

1reaction
dsehnalcommented, Nov 15, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found