/** * Created by jimsugg on 9/18/16. */ import { DmSignState } from '../baDmInterfaces' import { DmInternal } from "../baDmClasses"; import { BaDmId, BaDmIdNone, VideoMode, VideoModeName } from '../baDmDataTypes'; import { SignAction, SignParams } from '../baDmActions' import { NEW_SIGN, OPEN_SIGN } from "../baDmActions"; // The present implementation assumes that the state holds only one sign // at a time. Conceivably, the data model could hold multiple signs. // For such a case, container reducers (such as those for zones) would // be required, and zones would have container properties to identify their // containing sign. type DmState = DmInternal.DmState; // Return a simple object conforming to DmSignState const createSignState = (id: BaDmId, name: string, videoMode: VideoMode) => ({ id: BaDmIdNone, // not needed unless we support multiple signs name: name, videoMode: videoMode }); const newSignState = createSignState(BaDmIdNone, "Untitled", VideoMode.v1920x1080x60p); const signReducer = (state: DmSignState = newSignState, {type, id, payload}: SignAction) => { switch (type) { case NEW_SIGN: let {name, videoMode} = payload; return createSignState(id, name, videoMode); } return state; }; // Selectors export const getSignMetadata = (state: DmState) => new DmInternal.Sign(state.sign); export const getSignName = (state: DmState) => state.sign.name; export const getSignVideoMode = (state: DmState) => state.sign.videoMode; export const getSignVideoModeName = (state: DmState) => VideoModeName[state.sign.videoMode]; export default signReducer;