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

Passing falsy payload leads to action without payload property #15

Closed
martynaskadisa opened this issue Feb 19, 2019 · 1 comment
Closed
Assignees
Labels
bug Something isn't working

Comments

@martynaskadisa
Copy link

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 the-dr-lazy added bug Something isn't working help wanted Extra attention is needed good first issue Good for newcomers labels Feb 20, 2019
@the-dr-lazy
Copy link
Owner

the-dr-lazy commented Feb 20, 2019

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

the-dr-lazy pushed a commit that referenced this issue Feb 20, 2019
## [1.1.1](v1.1.0...v1.1.1) (2019-02-20)

### Bug Fixes

* attach non-undefined falsy values to payload and meta of action ([1fd8ed8](1fd8ed8)), closes [#15](#15)
@the-dr-lazy the-dr-lazy self-assigned this Feb 20, 2019
@the-dr-lazy the-dr-lazy removed good first issue Good for newcomers help wanted Extra attention is needed labels Mar 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants