Hyperapp: Remove reference to payload filters from tutorial

Created on 8 Jul 2020  路  3Comments  路  Source: jorgebucaran/hyperapp

Currently the tutorial on the website references payload filters.
This was _experimental_ functionality and will be removed in the future (v2).

Ref: https://github.com/jorgebucaran/hyperapp/blob/minimizations/docs/tutorial.md#payloadfilters

Most helpful comment

@zaiste The trick is that an action can return an action too (=> [MyAction, newPayload]), so I usually define a function to help me with that.

const withPayload = (filter) => (_, x) => filter(x)

and use it like this for example:

{
  oninput: withPayload((event) => [
    MyAction,
    { id: state.currentId, value: event.target.value },
  ]),
}

The action that carries the payload is the anonymous function in the middle (_, x) of withPayload.

We could (and probably should) export that from @hyperapp/events, as I also want to include higher level event utilities. e.g:

const targetValue = (action) =>
  withPayload(({ target: { value } }) => [action, value])

All 3 comments

@dwknippers what's the proper alternative in this scenario?

@zaiste The trick is that an action can return an action too (=> [MyAction, newPayload]), so I usually define a function to help me with that.

const withPayload = (filter) => (_, x) => filter(x)

and use it like this for example:

{
  oninput: withPayload((event) => [
    MyAction,
    { id: state.currentId, value: event.target.value },
  ]),
}

The action that carries the payload is the anonymous function in the middle (_, x) of withPayload.

We could (and probably should) export that from @hyperapp/events, as I also want to include higher level event utilities. e.g:

const targetValue = (action) =>
  withPayload(({ target: { value } }) => [action, value])

This has been adressed in #994 We can close here I think

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jscriptcoder picture jscriptcoder  路  4Comments

jbrodriguez picture jbrodriguez  路  4Comments

SkaterDad picture SkaterDad  路  3Comments

zaceno picture zaceno  路  4Comments

dmitrykurmanov picture dmitrykurmanov  路  3Comments