
Research
Two Malicious Rust Crates Impersonate Popular Logger to Steal Wallet Keys
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
redux-saga-callback
Advanced tools
In a normal flow of a redux-saga application there might be some cases that you want get notified when a saga triggered by a dispatched action is completed. The purpose of this library is to provide some helper functions to achieve that functionalities.
In a normal flow of a redux-saga application there might be some cases that you want get notified when a saga triggered by a dispatched action is completed. The purpose of this library is to provide some helper functions to achieve that functionalities.
npm i redux-saga-callback
import { putWait, withCallback } from 'redux-saga-callback';
Wrap your saga generator with withCallback
takeEvery('FETCH_USERS', withCallback(fetchUsers));
Defined callback in your action if you need
dispatch({type: 'FETCH_USERS', onComplete: ({error, cancelled, data}) => {
}})
In saga you can wait for it (no callback definition is needed with putWait)
const users = yield putWait({type: 'FETCH_USERS'});
This is a higer order saga which will call the onComplete callback property of the action if defined.
onComplete
function onComplete({ error, cancelled, data }) {
/* handle callback */
}
function* fetchUsers() {
const users = yield fetch('/users');
// put users to store
yield put(putUsers(users));
// returned value will be passed to onComplete function as parameter
// Exceptions will be handled by the withCallback and will also be passed to onComplete
return users;
}
export function*(){
yield all([
takeEvery('FETCH_USERS', withCallback(fethcUsers))
])
}
// userSaga.js
// Component to list users
export const Users = () => {
const [isLoading, setIsLoading] = useState(true);
const [users, setUsers] = useState([]);
const dispatch = useDispatch();
function onUsersFetchCompleted({ error, cancelled, data }) {
setIsLoading(false);
if (!err && !cancelled) {
setUsers(data);
}
}
useEffect(() => {
dispatch({
type: 'FETCH_USERS',
onComplete: onUsersFetchCompleted,
});
}, []);
return isLoading ? (
'Loading'
) : (
<ul>
{users.map(user => (
<li>{user.name}</li>
))}
</ul>
);
};
// Users.jsx
An effect that dispatches the action (same as put effect) which you can yield and wait for that saga to be completed only if the saga is created using withCallback higher order saga
Example
function* loadCurrentUserData() {
const currentUserId = getCurrentUserId();
let users = yield select(state => state.users);
if(!users) {
// waits until fetchUsers saga is completed
// fetchUser saga is defined in userSaga.js above
users = yield putWait({type: 'FETCH_USERS'});
}
return users.find(p => p.id === currentUserId);
}
export function*(){
yield all([
takeEvery('LOAD_CURRENT_USER', fethcUsers)
])
}
// userData.js
FAQs
In a normal flow of a redux-saga application there might be some cases that you want get notified when a saga triggered by a dispatched action is completed. The purpose of this library is to provide some helper functions to achieve that functionalities.
We found that redux-saga-callback 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.
Research
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
Research
A malicious package uses a QR code as steganography in an innovative technique.
Research
/Security News
Socket identified 80 fake candidates targeting engineering roles, including suspected North Korean operators, exposing the new reality of hiring as a security function.