Comments (11)
@jbucaran: nope nothing else :) That's perfect. It was the fact that data
was missing from the effect function signature that was throwing me. It's there now and all is well :)
from hyperapp.
Ah, so I can pass data to effects -- that's great news! But the docs should really reflect this (they mention data for update-reducers but not effects).
from hyperapp.
Let's say you have this
'use strict'
const { app, html } = hyperapp
app({
model: {
text: 'init'
},
view: (model) => html`<h1>${model.text}</h1>`,
hooks: {
onError: (err) => console.log('huh, err!', err.message)
},
update: {
first: (model, data) => ({ text: data.text + ' reducer' })
},
effects: {
foo: (model, msg, data, cb) => {
msg.first({ text: data.text + 'effect '})
msg.bar({ text: data.text + model.text + ' from foo' })
.then((message) => {
throw new Error(message)
})
.catch(cb)
},
bar: (model, msg, data) => {
return new Promise((_) => {
resolve(data.text + 'bar')
})
}
},
subs: [
(model, msg) => msg.foo({ text: 'on load ' })
]
})
from hyperapp.
But since effects don't take any parameters (as per the docs)
That's not true. Every action can be passed with arguments, actually single data
argument, through the views. It is easy as msg.action(data)
. If you want to call other effect from some effect you can do it too.
app({
effects: {
foo: (model, msg, data, done) => {
msg.bar({ bar: data.bar + model.bar + ' from foo' })
},
bar: (model, msg, data, done) => console.log(data)
}
})
from hyperapp.
Yep, we should make the docs better, definitely, haha.
from hyperapp.
@tunnckoCore what does done
do?
from hyperapp.
@dodekeract done
is that error
. it is just options.onError
function and it throws given error by default, but you can change this behaviour.
It is just common to call such arguments next
, done
, cb
and etc
edit: because it kinda "follows" the node's "error first callbacks" convention - cb(err)
.
from hyperapp.
@zaceno It's hard to find, but it's there. I think I can improve this bit of the docs by adding a note to the effects section in the README. Thanks for pointing it out.
from hyperapp.
in addition to the screenshot: "where data
is any data you want to pass to the action
which is reducer / effect"
from hyperapp.
@tunnckoCore Good point, will fix!
from hyperapp.
@zaceno Docs have been updated. See https://github.com/hyperapp/hyperapp#effects
Let me know if that's good enough or we need to address anything else.
from hyperapp.
Related Issues (20)
- A way to insert raw Html HOT 1
- TypeError: can't access property 0, newSubs is null, when setting the state to undefined. HOT 4
- Issue with null-vnodes HOT 1
- prevent rerender node HOT 2
- The dispatch initializer ends in an endless loop on init when dispatching any action HOT 7
- Injected classes gets removed when using object/array to define class props HOT 1
- hyperapp version HOT 3
- Memo Data Gotcha HOT 5
- Confusing doc for actions -> wrapped actions HOT 5
- Passing arguments to init HOT 4
- [Question] Headless mode is still possible? HOT 1
- Destroying a child app HOT 8
- @hyperapp/html: use a Proxy? HOT 9
- Actions returning other Actions HOT 5
- Compile template tag to hyperscript HOT 17
- A challenge to hyperapp community HOT 1
- Has 2.0 been dropped from development? HOT 3
- oldSub[2] is not a function HOT 3
- Cannot read properties of null (reading 'length') HOT 5
- Unlikely Use Case bug in HTML and SVG Packages HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hyperapp.