the-dr-lazy / deox

Functional Type-safe Flux Standard Utilities
https://deox.js.org
MIT License
206 stars 12 forks source link

Passing falsy payload leads to action without payload property #15

Closed martynaskadisa closed 5 years ago

martynaskadisa commented 5 years ago

I've started using this library on a fresh project, looks really promising. However I've noticed one issue. When passing falsy values to action creator it seems to not get attached to the created action.

Example:

export const setOpen = createAction(
  'SET_OPEN',
  resolve => (payload: boolean) => resolve(payload)
);

setOpen(true)
// { type: 'SET_OPEN', payload: true } <- all good

setOpen(false)
// { type: 'SET_OPEN' } <- missing payload property
export const setCount = createAction(
  'SET_COUNT',
  resolve => (payload: number) => resolve(payload)
);

setCount(1)
// { type: 'SET_COUNT', payload: 1 } <- all good

setCount(0)
// { type: 'SET_COUNT' } <- payload is missing

Seems to be related to here: https://github.com/thebrodmann/deox/blob/b7be530ec77ce81f24692f7438daeebfea7b74a7/src/action.ts#L81

Passing any falsy value would make payload not appear on created action. Maybe action function could at least check if that value is undefined and then ignore payload, otherwise just add payload?

the-dr-lazy commented 5 years ago

@martynaskadisa I'm so grateful to you for your contribution.

Passing any falsy value would make payload not appear on created action. Maybe action function could at least check if that value is undefined and then ignore payload, otherwise just add payload?

I'm agree with you. Also there is a similar problem with any falsy meta.