Using Choo to create reusable widgets?
See original GitHub issueI wanted to see if I could use choo to create a widget that I can add to any HTML page. I had the following requirements:
- Ability to pass in options to customize the created DOM element
- Imperatively call methods on the element to trigger actions
- Handle events triggered by the element
- Have more than once instance of the element on a page
Was choo built to handle this? I noticed that all examples require the router to configured for example. I would not need this and I am interested to know if choo can be used without it. What I would want to use is the model and the view functionality.
I hacked together a POC of how this could be done. You can look at the jsbin here. It works but, as I said it’s kind of hacky. My problem was really that I needed to get access to the send
function, to be able to attach it to the element instance, in order to be able to call a function on the rendered element. The only way I could think to do it was to expose the send
function outside of the main view.
So, is there a better way?
By the way, great framework. It’s really fun!
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:13 (6 by maintainers)
Top GitHub Comments
We should probably document this a bit further in the handbook, but https://www.npmjs.com/package/nanocomponent is a thing now ✨
Yay, glad to hear! Re: your issue - we’re currently working on nanomorph; perhaps that yields a better result? https://github.com/yoshuawuyts/nanomorph
On Sun, Jan 8, 2017 at 8:20 PM Ricky Reusser notifications@github.com wrote: