Implement default “setTransient” action

This commit is contained in:
Philipp Stracker 2025-01-27 11:00:22 +01:00
parent 9fdc370c21
commit 78a6303e12
No known key found for this signature in database

View file

@ -37,27 +37,17 @@ export const hydrate = ( payload ) => ( {
} );
/**
* Transient. Marks the store as "ready", i.e., fully initialized.
* Generic transient-data updater.
*
* @param {boolean} isReady
* @param {string} prop Name of the property to update.
* @param {any} value The new value of the property.
* @return {Action} The action.
*/
export const setIsReady = ( isReady ) => ( {
export const setTransient = ( prop, value ) => ( {
type: ACTION_TYPES.SET_TRANSIENT,
payload: { isReady },
payload: { [ prop ]: value },
} );
/**
* Side effect. Triggers the persistence of store data to the server.
*
* @return {Action} The action.
*/
export const persist = function* () {
const data = yield select( STORE_NAME ).persistentData();
yield { type: ACTION_TYPES.DO_PERSIST_DATA, data };
};
/**
* Generic persistent-data updater.
*
@ -69,3 +59,22 @@ export const setPersistent = ( prop, value ) => ( {
type: ACTION_TYPES.SET_PERSISTENT,
payload: { [ prop ]: value },
} );
/**
* Transient. Marks the store as "ready", i.e., fully initialized.
*
* @param {boolean} isReady
* @return {Action} The action.
*/
export const setIsReady = ( isReady ) => setTransient( 'isReady', isReady );
/**
* Side effect. Triggers the persistence of store data to the server.
*
* @return {Action} The action.
*/
export const persist = function* () {
const data = yield select( STORE_NAME ).persistentData();
yield { type: ACTION_TYPES.DO_PERSIST_DATA, data };
};