Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Q: Inline onload supposed to work ? #570

Closed
antenando opened this issue Sep 29, 2017 · 7 comments
Closed

Q: Inline onload supposed to work ? #570

antenando opened this issue Sep 29, 2017 · 7 comments

Comments

@antenando
Copy link

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!

@goto-bus-stop
Copy link
Member

goto-bus-stop commented Sep 29, 2017

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: choojs/nanohtml#76 (comment)

@antenando
Copy link
Author

Not a problem. Thanks for the background! Cheers

@antenando
Copy link
Author

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.

@graforlock
Copy link
Member

graforlock commented Sep 29, 2017

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

```javascript
const div = html<div></div>

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.

@goto-bus-stop
Copy link
Member

goto-bus-stop commented Sep 29, 2017

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.

@graforlock
Copy link
Member

graforlock commented Sep 29, 2017

EDIT:

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

Use shama/on-load then

@yoshuawuyts
Copy link
Member

yoshuawuyts commented Sep 30, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants