Code Monkey home page Code Monkey logo

Comments (11)

zaceno avatar zaceno commented on April 27, 2024 3

@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.

zaceno avatar zaceno commented on April 27, 2024 1

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.

tunnckoCore avatar tunnckoCore commented on April 27, 2024 1

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.

tunnckoCore avatar tunnckoCore commented on April 27, 2024

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.

tunnckoCore avatar tunnckoCore commented on April 27, 2024

Yep, we should make the docs better, definitely, haha.

from hyperapp.

FlorianWendelborn avatar FlorianWendelborn commented on April 27, 2024

@tunnckoCore what does done do?

from hyperapp.

tunnckoCore avatar tunnckoCore commented on April 27, 2024

@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.

jorgebucaran avatar jorgebucaran commented on April 27, 2024

@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.

screen shot 2017-02-09 at 11 13 45

from hyperapp.

tunnckoCore avatar tunnckoCore commented on April 27, 2024

in addition to the screenshot: "where data is any data you want to pass to the action which is reducer / effect"

from hyperapp.

jorgebucaran avatar jorgebucaran commented on April 27, 2024

@tunnckoCore Good point, will fix!

from hyperapp.

jorgebucaran avatar jorgebucaran commented on April 27, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.