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.

Widgets with choo

See original GitHub issue

I’m trying to create a reusable element that implements Quill but I can’t figure out how to do it. The issue I’m having is that on re-render the Quill editor gets wiped; I don’t know how to maintain the state of it.

The most basic example:

const html = require('choo/html')
const onload = require('on-load')
const Quill = require('quill')

module.exports = richtext

function richtext (state, prev, send) {
  const div = html`<div></div>`
  onload(div, (el) => {
    const quill = new Quill(el)
    quill.on('text-change', () => {
      send() // triggers re-render and DOM state is lost
    })
  })
  return div
}

I used virtual-widget a while back - something like that would be ideal for this.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
yoshuawuytscommented, Oct 5, 2016

Yay, all the PRs have been merged and it should all be working. As per #1 we’re now building out cache-element/widget which should allow for super clean widgetization of elements ✨ The API looks like this:

const widget = require('cache-element/widget')
const html = require('bel')

const renderEl = widget(function (update) {
  let name = null
  let age = null

  update(onupdate)

  return html`
    <p onload=${onload} onunload=${onunload}>
      Name is ${name} and age is ${age}
    </p>
  `

  function onupdate (newName, newAge) {
    name = newName
    age = newAge
  }

  function onload () {
    console.log('added to DOM')
  }

  function onunload () {
    name = null
    age = null
    console.log('removed from DOM')
  }
})

let el = renderEl('Tubi', 12) // creates new element
let el = renderEl('Tubi', 12) // returns cached element (proxy)
let el = renderEl('Babs', 25) // returns cached element (proxy)

I think this should answer your question; consider watching / contributing to cache-element to get this out faster, but in essence all the lower level components now work and exist 😁

0reactions
yoshuawuytscommented, Sep 10, 2016

waiting on https://github.com/patrick-steele-idem/morphdom/issues/77 to be published; made a demo on how to create widgets with the isSameNode() API here: https://github.com/shama/on-load/issues/10#issuecomment-246118634 (e.g. thunking!)

This should provide exactly the experience we intended to have from the start 🎉

Read more comments on GitHub >

github_iconTop Results From Across the Web

dog Memo Widget for iPhone & Android by Choo Choo7264 ...
With Widget club, you can customize from various kinds of stunning widgets and icon pack and create your own easily! and also, you...
Read more >
How to Create and Add Widgets on an iPhone - Howchoo
How to Create and Add Widgets on an iPhone · Widget Creation Steps: · Press and Hold · Click the Plus Sign ·...
Read more >
How to Use the Pokemon Go Egg Hatching Widget
This widget, actually called Adventure Sync: Egg, is a widget that tracks your egg-hatching progress when Pokemon GO is in the background.
Read more >
The Art of Flutter: Widget Explained | by Jason Choo - Medium
Flutter provides a comprehensive range of pre-built widgets that cover most of the use cases to develop your desired user interfaces with ...
Read more >
Routing - Choo
This chapter is intended to give an overview of how routing works in Choo. ... need routing at all, for example when using...
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