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.

[Help Wanted] How to easily override existing component ?

See original GitHub issue

For example, I want to add a double click event handler on the default video component to open the assets manager.

let v = editor. DomComponents.getType('video')
let view = v.view()

My basic idea was to get the view definition of the video component and add events + handler. At last, set it back to the video component.

Unfortunately, this idea failed in the first step. v.View() gives me an error

TypeError: this._ensureElement is not a function
    at Object.e.View (grapes.min.js?e1c1:2)
    at Object.r (grapes.min.js?e1c1:2)
    at Object.r (grapes.min.js?e1c1:2)
    at Object.r (grapes.min.js?e1c1:2)
    at VueComponent.configVideo (HelloWorld.vue?18db:218)
    at VueComponent.mounted (HelloWorld.vue?18db:88)
    at invokeWithErrorHandling (vue.esm.js:formatted:1729)
    at callHook (vue.esm.js:formatted:3882)
    at Object.insert (vue.esm.js:formatted:2877)
    at invokeInsertHook (vue.esm.js:formatted:5887)

I am new to this project and barely know about Backbone.js. Would you please offer me some suggestions?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
archerbjcommented, Nov 12, 2020

@archerbj here’s a demo of what you’re looking for: https://codesandbox.io/s/sharp-easley-3hrdn?file=/index.js

You want to attach the functionality to the component type itself rather than trying to find all instances of that component and add it on some change. So to do that, create a new Component Type that extends the video type then add the dblclick event handler to the view. Once you’ve got that, then you create a block that uses your new component type.

Here is some documentation on how to extend component types and here’s the guide on creating a custom block

Hope this helps.

Josh

Thanks a lot! I missed that part in the docs. I’ll try to figure it out

1reaction
Joshmamroudcommented, Nov 11, 2020

@archerbj here’s a demo of what you’re looking for: https://codesandbox.io/s/sharp-easley-3hrdn?file=/index.js

You want to attach the functionality to the component type itself rather than trying to find all instances of that component and add it on some change. So to do that, create a new Component Type that extends the video type then add the dblclick event handler to the view. Once you’ve got that, then you create a block that uses your new component type.

Here is some documentation on how to extend component types and here’s the guide on creating a custom block

Hope this helps.

Josh

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Override Existing React Components | Pluralsight
Read this guide to learn how to override existing React.js class. ... hinder the straightforward employment of existing components:.
Read more >
Apply overrides to instances - Components - Figma Help Center
It's not possible to make changes to the underlying structure of an instance. You can't override: The order, or z-index, of any layers...
Read more >
In Castle Windsor 3, override an existing component ...
There are two things that you have to do to create an overriding instance: Assign it a unique name; Call the IsDefault method....
Read more >
Better Reusable React Components with the Overrides Pattern
We wanted to come up with a unified API across our components that ... we created a component override for Tag which rendered...
Read more >
Overriding Built-in Components - Builder.io
You can override Builder-provided components by registering a custom component with the same name. By overriding a component, you can add extra features...
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