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

Creating action with undefined payload converts to {} #47

Open
mischkl opened this issue Sep 21, 2018 · 2 comments
Open

Creating action with undefined payload converts to {} #47

mischkl opened this issue Sep 21, 2018 · 2 comments

Comments

@mischkl
Copy link

mischkl commented Sep 21, 2018

I just ran into this issue after upgrading to 2.x, which has caused a serious bug in our application.

Using an action creator without specifying a payload, for an action that expects a payload (created with typeOf), results in the payload being "autogenerated" as the empty object {}. This is a serious issue because sometimes we want to pass on the fact that there is no value being passed.

We managed to work around the issue by converting to null when calling the action creator, e.g. MyActionType.DoSomething(value || null). However this seems to be an unnecessary burden for developers to always have to do this.

@pelotom
Copy link
Owner

pelotom commented Sep 22, 2018

Can you provide a full, self-contained code snippet to illustrate what you mean? I'm not sure I follow.

@mischkl
Copy link
Author

mischkl commented Oct 8, 2018

Hi, sorry for the delayed response.

Here is an example:

// actions
export const UserActions = unionize({
  GetAllUsers: {},
  GetAllUsersSuccess: ofType<User[]>(),
  SelectUser: ofType<string>()
}, {tag: 'type', value: 'payload'});

// use of action creator
const selectedUser = getLoggedInUser(); // returns undefined
const selectAction = UserActions.SelectUser(selectedUser);
// creates { type: 'SelectUser', payload: {} }
// expected behavior: { type: 'SelectUser', payload: undefined }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants