Commit 34ff4abc authored by René Jochum's avatar René Jochum

Format

parent 0381c66c
......@@ -19,7 +19,11 @@ export const addNode = <T>(obj: T, parentId = -1): AnyAction => ({
parentId
});
export const insertNode = <T>(obj: T, beforeId: number, where: number = INSERT_AFTER): AnyAction => ({
export const insertNode = <T>(
obj: T,
beforeId: number,
where: number = INSERT_AFTER
): AnyAction => ({
type: INSERT_NODE,
id: nextId++,
obj,
......@@ -52,9 +56,7 @@ export const toggleAllNodes = (
force
});
export const setActiveNode = (
id: number = -1
): AnyAction => ({
export const setActiveNode = (id: number = -1): AnyAction => ({
type: SET_ACTIVE_NODE,
id,
});
\ No newline at end of file
id
});
......@@ -7,7 +7,7 @@ import {
toggleNode,
toggleAllNodes,
INSERT_BEFORE,
setActiveNode,
setActiveNode
} from "../actions";
import { FlatTreeNode } from "../types/flattree";
import { Map, is, List } from "immutable";
......@@ -78,7 +78,7 @@ describe("reducer", () => {
expect(
is(
reducer(undefined, { type: "UNKNOWN" }),
Map({ nodes: List([]), activeNode: -1})
Map({ nodes: List([]), activeNode: -1 })
)
).toBeTruthy();
});
......@@ -86,13 +86,13 @@ describe("reducer", () => {
it("should handle the SET_ACTIVE_NODE action", () => {
const stateBefore = testTree;
const action = setActiveNode(6);
const stateAfter = testTree.set('activeNode', 6);
const stateAfter = testTree.set("activeNode", 6);
expect(is(reducer(stateBefore, action), stateAfter)).toBeTruthy();
});
it("should handle ADD_NODE action", () => {
const stateBefore = Map({ nodes: List([]), activeNode: -1});
const stateBefore = Map({ nodes: List([]), activeNode: -1 });
const action = addNode(false);
const stateAfter = Map({
nodes: List<BooleanNode>([
......@@ -103,7 +103,7 @@ describe("reducer", () => {
obj: false
})
]),
activeNode: -1,
activeNode: -1
});
expect(is(reducer(stateBefore, action), stateAfter)).toBeTruthy();
......
......@@ -67,7 +67,7 @@ function _insertNode<T>(
state: FlatTreeList<T>,
action: AnyAction
): FlatTreeList<T> {
const beforeIdx = state.findIndex((x) => x.get('id') === action.beforeId);
const beforeIdx = state.findIndex(x => x.get("id") === action.beforeId);
if (beforeIdx === -1) {
let newNode = new FlatTreeNode<T>({
......@@ -90,7 +90,7 @@ function _insertNode<T>(
return state.insert(beforeIdx, newNode);
}
return state.insert(beforeIdx+1, newNode);
return state.insert(beforeIdx + 1, newNode);
}
function _removeNode<T>(
......@@ -215,10 +215,7 @@ function nodes<T>(
};
}
const activeNode = (
state: number | undefined = -1,
action: AnyAction
) => {
const activeNode = (state: number | undefined = -1, action: AnyAction) => {
switch (action.type) {
case SET_ACTIVE_NODE:
return action.id;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment