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.

[QUESTION] Update component view on property change

See original GitHub issue

Hi everyone, I’m trying to create a component that will update it’s view based on a property value

editor.DomComponents.addType("price-value-type", {
            isComponent: el => {
              if (el.tagName == "div" && el.hasAttribute("price-value")) {
                return { type: "price-value-type" };
              }
            },
            model: {
              defaults: Object.assign({}, defaultProperties, {
                defaultPrice: 0,
                name: "Price",
                classes: ["price"],
                components: model => {
                  return `${model.get("defaultPrice")}`}
              })
            },
            extendView: 'default',
            extendFnView: ['render'],
            view: {
              init() {
                console.log(this.render);
                this.listenTo(this.model, 'change:defaultPrice', this.render);
              },
              // render() {
              //   this.el.innerHTML = this.model.get("defaultPrice");
              // }
            }
          });

My approach is bassed on #1227 and on the docs In my use case I don’t need the trait, I can just update the property programmatically. But this won’t work and will not display any component on the canvas even though they are on the layer manager as we can see here(they show properly with the render function commented) maybe i’m missing something?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
artfcommented, Feb 4, 2020

to update the HTML you have to change toHTML in the model

model: {
	...
	toHTML() {
		const tagName = this.get('tagName');
		const price = this.get('defaultPrice');
		return `<${tagName}>${price}</{tagName}>`;
	}
}
1reaction
rjrodriguezalvarez97commented, Feb 4, 2020

I’ll give it a try the day after tomorrow. Thanks for your quick replies!

Read more comments on GitHub >

github_iconTop Results From Across the Web

View doesn't update on component property change in ...
The problem I am having is that the bindings in the view don't seem to update the first time I call the service,...
Read more >
LWC - Component not Rerendering when Property Changes
I assign the updated information to an array but the component does not rerender and therefore does not call a child component to...
Read more >
How to Observe Property Changes with LitElement and ...
This method will be called when an element should be updated based on a component state or property change. It's a good place...
Read more >
48 answers on StackOverflow to the most popular Angular ...
I'm writing an Angular component that has a property Mode(): string . I would like to be able to set this property programmatically...
Read more >
Explore component properties - Figma Help Center
Component properties are the changeable aspects of a component. You can define which parts of a component others can change by tying them...
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