Skip to content

Commit

Permalink
refactor: remove lodash omit
Browse files Browse the repository at this point in the history
  • Loading branch information
FabienMotte committed Feb 13, 2017
1 parent fe3cf1e commit 5742923
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@
"dependencies": {
"lodash.clonedeep": "^4.5.0",
"lodash.isequal": "4.5.0",
"lodash.omit": "^4.5.0",
"quark-signal": "1.1.0"
}
}
34 changes: 16 additions & 18 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import Signal from 'quark-signal'

import isEqual from 'lodash.isequal'
import omit from 'lodash.omit'
import cloneDeep from 'lodash.clonedeep'

/**
Expand Down Expand Up @@ -44,7 +43,7 @@ class State {
throw new Error('State.get() : Cannot get a value from a container that does not exist')
}

let value = container
let value = container.tree

if (splittedQuery.length > 1) {
for (let i = 1, l = splittedQuery.length; i < l; i++) {
Expand All @@ -56,11 +55,6 @@ class State {
}
}

// If it is a container, omit 'signals' property
if (splittedQuery.length === 1) {
return omit(value, 'signals')
}

return value
}

Expand All @@ -80,27 +74,29 @@ class State {
throw new Error('State.set() : Cannot set a value on a container that does not exist')
}

let target = this._containers
for (let i = 0, l = splittedQuery.length; i < l; i++) {
const p = splittedQuery[i]
const oldVal = target[p]
let target = container.tree
const slicedQuery = splittedQuery.slice(1)

if (typeof target[p] !== 'object') {
target[p] = {}
for (let i = 0, l = slicedQuery.length; i < l; i++) {
const prop = slicedQuery[i]
const oldVal = target[prop]

if (typeof target[prop] !== 'object' && target[prop] !== null) {
target[prop] = {}
}

if (i === splittedQuery.length - 1) {
if (i === slicedQuery.length - 1) {
if (typeof oldVal === 'undefined' || typeof value !== 'object' || value === null || forced) {
target[p] = value
target[prop] = value
} else {
target[p] = {
target[prop] = {
...oldVal,
...value
}
}
}

target = target[p]
target = target[prop]

let signalId = containerId
for (let j = 1; j <= i; j++) {
Expand Down Expand Up @@ -206,7 +202,9 @@ class State {
throw new TypeError('State.initContainer() : Second argument must be an Object')
}

this._containers[containerId] = cloneDeep(value)
this._containers[containerId] = {}

this._containers[containerId].tree = cloneDeep(value)
this._containers[containerId].signals = {}
}

Expand Down

0 comments on commit 5742923

Please sign in to comment.