Security News
cURL Project and Go Security Teams Reject CVSS as Broken
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
the-actions
Advanced tools
Refine the actions in TypeScript context.
type
to be string literal.ActionCreator
could be implemented in 4 lines of pretty-printed code.meta
and error
have rarely usecases.payload
is type-safe without checking error
.meta
and error
besides payload
.the-actions
doesn't change the way to create a 'reducer'.type
no more than ONCE
type
anywhere? No point at all!type
.the-actions
doesn't reject to work with other-system actions if they do too.the-actions
can be integrated into redux (reducer), redux-saga (take*), react hooks (useReducer), and anything need to mark a type for channeling, which exceeds the react & redux ecosystem.// create an action creator
import { ActionCreator } from "the-actions";
const setText = ActionCreator<{ text: string }>();
// create an action
const setTextAction = setText({ text: "hello, world" });
// usage in redux reducer
const initState = { text: "" };
const reducer = (state = initState, action: unknown) => {
if (setText.match(action)) {
return { ...state, text: action.payload.text };
}
return state;
};
// usage in react-redux connect
import { bindActionCreators, Dispatch } from "redux";
const mapDispatchToProps = (dispatch: Dispatch) =>
bindActionCreators(
{
setText,
},
dispatch,
);
// usage in redux-saga
import { call, takeLatest } from "redux-saga/effects";
function* saga() {
yield takeLatest(setText.match, sampleListener);
}
function* sampleListener(action: ReturnType<typeof setText>) {
yield call(console.log, action.payload.text);
}
// usage in react useReducer hook
import React, { useReducer } from "react";
const InputComponent = () => {
const [state, dispatch] = useReducer(reducer, initState);
return (
<input
value={state.text}
onChange={(e: React.ChangeEvent<HtmlInputElement>) => {
dispatch(setText(e.target.value));
}}
/>
);
};
Yes, there's many action utilities published. And some of them are designed for typescript.
up to now, there're many in npm, includes typesafe-actions
, typescript-fsa
, ts-action
, typed-redux-actions
, create-action-ts
, redux-action-class
...
Take the most typical for examples,
typescript-fsa
It's almost what I want!
The core mechanisms are the same except the-actions
is not fully FSA-compliant. In fact, the-actions
loaded meta
and error
off to be simple.
By the way, it's a amazing coincidence that typescript-fsa
and the-actions
took the same word "match" to name the type predicate.
Another difference is that the-actions
doesn't treat the "Async Action Creators" as first-class concept. In the-actions
, "Async Action Creators" is a sample of "Action Creator Group", which is a composition of action creators.
Further more, when creating an action creator in typescript-fsa
, you MUST pass a type
for identify the action creator. It's no problem but lose the chance to entirely avoid specifying a unique string.
typesafe-actions
The core mechanisms to be type-safe are really different.
The way of typesafe-actions
is troublesome.
type
MUST BE string literal (Ability Limited)
It stopped writing prefix (namespace) for the action type.
Actions SHOULD BE united first (Boilerplate Code)
That is, you, the app developper, should define the universal set of action for every reducer. And then, typescript helps narrowing the scope from the universal set.
So, typesafe-actions
paid too much for type-safe.
FAQs
Refine the actions in TypeScript context
The npm package the-actions receives a total of 7 weekly downloads. As such, the-actions popularity was classified as not popular.
We found that the-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
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.