Security News
Highlights from the 2024 Rails Community Survey
A record 2,709 developers participated in the 2024 Ruby on Rails Community Survey, revealing key tools, practices, and trends shaping the Rails ecosystem.
ts-redux-actions
Advanced tools
Redux helpers for Type-safety (action types & action creators)
main
module
jsnext:main
I wasn't satisfied with the API design in redux-actions. The reason was because of the specific API design (allowing multiple args for action creator) and separate payload, meta map functions which is not good for static typing in TypeScript.
It doesn't allow for correct type inference and will force you to do an extra effort for explicit type annotations and produce more boilerplate.
The most issues with redux-actions
types are related to losing your function definition intellisense and named arguments in resulting action creator which for me is unacceptable.
In examples part I will show you exactly the difference in API design but also between resulting (action creators) definitions coming from my solution and from redux-actions
so you can clearly see the benefits.
For more advanced usage scenarios please check use cases described in test specification
createAction(type, creatorFunction?)
type: string,
creatorFunction: (type: T) => (...args: any[]) => { type: T, payload?: P, meta?: M }
return: (...args: any[]) => { type: T, payload?: P, meta?: M }
Examples:
it('no payload', () => {
const increment = createAction('INCREMENT');
expect(increment()).toEqual({ type: 'INCREMENT' });
expect(increment.type).toBe('INCREMENT');
});
it('with payload', () => {
const add = createAction('ADD', (type: 'ADD') => (amount: number) =>
({ type, payload: amount }),
);
expect(add(10)).toEqual({ type: 'ADD', payload: 10 });
expect(add.type).toBe('ADD');
});
it('with payload and meta', () => {
const notify = createAction('NOTIFY', (type: 'NOTIFY') =>
(username: string, message: string) => ({
type,
payload: { message: `${username}: ${message}` },
meta: { username, message },
}),
);
expect(notify('Piotr', 'Hello!')).toEqual({
type: 'NOTIFY',
payload: { message: 'Piotr: Hello!' },
meta: { username: 'Piotr', message: 'Hello!' },
});
expect(notify.type).toBe('NOTIFY');
});
(WIP)
MIT License
Copyright (c) 2017 Piotr Witek piotrek.witek@gmail.com (http://piotrwitek.github.io)
FAQs
Typesafe Redux Action Creators for TypeScript
The npm package ts-redux-actions receives a total of 2 weekly downloads. As such, ts-redux-actions popularity was classified as not popular.
We found that ts-redux-actions demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A record 2,709 developers participated in the 2024 Ruby on Rails Community Survey, revealing key tools, practices, and trends shaping the Rails ecosystem.
Security News
In 2023, data breaches surged 78% from zero-day and supply chain attacks, but developers are still buried under alerts that are unable to prevent these threats.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.