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

Make api.save/load work with numbers rather than {value: number} #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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