Choo: Q: Inline onload supposed to work ?

Created on 29 Sep 2017  Â·  7Comments  Â·  Source: choojs/choo

Greetings from Brazil!

First of all, my sincere congrats for this amazing fw.

I have a simple question.

Why doesn't the inline onload work at the case below?

import choo from 'choo'
import html from 'choo/html'
import log from 'choo-log'
import onload from 'on-load'

export const testView = (state, emit) => {

    function onloadFn(el) {
        console.log('onLoad!', el);
    }

    return html`
        <div onload=${onloadFn}>
            <h1>test!</h1>
        </div>
    `
}

const app = choo()
app.use(log())
app.route('*', testView)
app.mount('#root')

but this does work ?

import choo from 'choo'
import html from 'choo/html'
import log from 'choo-log'
import onload from 'on-load'

export const testView = (state, emit) => {

    function onloadFn(el) {
        console.log('onLoad!', el);
    }

    const tree = html`
        <div>
            <h1>test!</h1>
        </div>
    `

    onload(tree, onloadFn)

    return tree
}

const app = choo()
app.use(log())
app.route('*', testView)
app.mount('#root')

What am I doing wrong?

Would love to understand it better.

Keep it up!

All 7 comments

choo@6 uses bel@5, which no longer includes the onload and onunload attributes. You have to do it like in your second snippet now, or turn your view into a nanocomponent.

some background: https://github.com/shama/bel/pull/76#issuecomment-302972958

Not a problem. Thanks for the background! Cheers

Just another quick one: is there an official central and up to date repository for the documentation?

I always find bits and pieces of code for things that doesn't work anymore with Choo.

In regards to the the initial question, you can just do

``javascript~~ ~~const div = html

`

div.onload = () => {}
```

as well, or as said before, with shama/on-load

About documentation, not really as those things come from third party APIs, choo is just opinionated high level architecture around these libraries/tools. Check what choo uses, and thats it.

I don't think you can do that, bel compiled <div onload=${xyz} /> to onload(el, xyz) before v5. div.onload = xyz is something different.

e;

Just another quick one: is there an official central and up to date repository for the documentation?

Not to my knowledge, there is the choo handbook tutorial but API documentation is in each individual module.

EDIT:

Well actually it won't really work on divs in particular so discard me.

Use shama/on-load then

Heya, sorry that docs aren't up to date - will be focusing (full time) on
getting more out in the next few weeks; so stay tuned! :D

On Fri, Sep 29, 2017 at 9:39 AM Maciej Sitko notifications@github.com
wrote:

It is something different as it just does dom onload event, which is most
of the times a correct interface of GlobalEventHandlers

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/choojs/choo/issues/570#issuecomment-333128796, or mute
the thread
https://github.com/notifications/unsubscribe-auth/ACWleuJP9EWYJ4AROiuYVJ01UirMPhDqks5snPMFgaJpZM4Pok-c
.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jeffbski picture jeffbski  Â·  5Comments

sholtomaud picture sholtomaud  Â·  4Comments

nanaian picture nanaian  Â·  5Comments

NetOperatorWibby picture NetOperatorWibby  Â·  5Comments

rafaismyname picture rafaismyname  Â·  6Comments