Skip to content

Conversation

@christianchown
Copy link

Hello - running the example as is gives an error on loading.

api.save(...) gets passed a number:

Cmd.run(api.save, {
successActionCreator: actions.saveCountSuccess,
failActionCreator: actions.saveCountError,
args: [action.value],
})

export function saveCount(value: number): Action {
return {
type: SAVE_COUNT,
value,
};
}

but expects a Counter:

save: (counter: Counter): Promise<null> =>
flakify(() => {
localStorage.setItem('__counterValue', counter.value.toString());
return null;
}),

Similarly, api.load() resolves a Counter:

load: (): Promise<Counter> =>
flakify(() => {
const storedValue = parseInt(
localStorage.getItem('__counterValue') || '',
10
);
return {
value: storedValue || 0,
};
}),

but the action expects a number:

export function loadCountSuccess(value: number): Action {
return {
type: LOAD_COUNT_SUCCESS,
value,
};
}

This then leads to the state shape being wrong, and the element refusing to render (Objects are not valid React children).

This commit gets rid of Counter and has the api just deal with numbers.

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

Successfully merging this pull request may close these issues.

1 participant