def to_props(self, state: State): """Select number of figures from state""" layers = state.get("layers", {}) try: return (layers["figures"], ) except KeyError: pass
def reducer(state: State, action: Action): """ Reduce a change in state caused by the ToolsPanel""" state = copy.deepcopy(state) if action["kind"] == ON_TOGGLE_TOOL: if state.get("tools") is None: state["tools"] = {} state["tools"][action["tool_name"]] = action["value"] return state
def reducer(state: State, action: Action) -> State: """Reducer to handle web map tiling settings""" state = copy.deepcopy(state) kind = action["kind"] if kind in [SET_TILE, SET_LABEL_VISIBLE]: tree = state.get("tile", {}) if kind == SET_TILE: tree["name"] = action["payload"] elif kind == SET_LABEL_VISIBLE: tree["labels"] = action["payload"] state["tile"] = tree return state
def reducer(state: State, action: Action) -> State: """Combine state and action to produce new state""" state = copy.deepcopy(state) kind = action["kind"] if kind in [ ADD_LAYER, # NOTE: Not used any more SET_FIGURES, ON_REMOVE ]: # NOTE: Not used any more layers = state.get("layers", {}) state["layers"] = _layers_reducer(layers, action) elif kind == ON_ADD: # Traverse/build tree node = state for key in ("layers", "mode"): node[key] = node.get(key, {}) node = node[key] node.update({"state": "add"}) elif kind == ON_CLOSE: # Traverse/build tree index = action["payload"] node = state for key in ("layers", "index"): node = node.get(key, {}) del node[index] elif kind == ON_EDIT: # Traverse/build tree index = action["payload"] node = state for key in ("layers", "mode"): node[key] = node.get(key, {}) node = node[key] node.update({"state": "edit", "index": index}) elif kind == SAVE_LAYER: # Traverse/build tree index = action["payload"]["index"] settings = action["payload"]["settings"] node = state for key in ("layers", "index", index): node[key] = node.get(key, {}) node = node[key] node.update(settings) elif kind == SET_ACTIVE: # Traverse/build tree index = action["payload"]["row_index"] settings = {"active": action["payload"]["active"]} node = state for key in ("layers", "index", index): node[key] = node.get(key, {}) node = node[key] node.update(settings) return state