-
chrisgarrity authored
* Export initial states for each reducer * combine all gui reducers (excludes scratchPaint and intl) * combine all initial states to create default guiState for preloading in www * expect all of the gui state to be accessible at `state.scratchGui`
chrisgarrity authored* Export initial states for each reducer * combine all gui reducers (excludes scratchPaint and intl) * combine all initial states to create default guiState for preloading in www * expect all of the gui state to be accessible at `state.scratchGui`
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
targets.js 1.17 KiB
const UPDATE_TARGET_LIST = 'scratch-gui/targets/UPDATE_TARGET_LIST';
const initialState = {
sprites: {},
stage: {}
};
const reducer = function (state, action) {
if (typeof state === 'undefined') state = initialState;
switch (action.type) {
case UPDATE_TARGET_LIST:
return Object.assign({}, state, {
sprites: action.targets
.filter(target => !target.isStage)
.reduce(
(targets, target, listId) => Object.assign(
targets,
{[target.id]: {order: listId, ...target}}
),
{}
),
stage: action.targets
.filter(target => target.isStage)[0] || {},
editingTarget: action.editingTarget
});
default:
return state;
}
};
const updateTargets = function (targetList, editingTarget) {
return {
type: UPDATE_TARGET_LIST,
targets: targetList,
editingTarget: editingTarget,
meta: {
throttle: 30
}
};
};
export {
reducer as default,
initialState as targetsInitialState,
updateTargets
};