-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from dottostack/refactor/minimization
refactor: minimization and optimization code
- Loading branch information
Showing
9 changed files
with
49 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,12 @@ | ||
import { computed, take } from '../computed' | ||
|
||
export const query = (store, queries) => { | ||
return computed(() => { | ||
return Object.entries(queries).reduce( | ||
export const query = (store, queries) => | ||
computed(() => | ||
Object.entries(queries).reduce( | ||
(acc, [queryKey, queryParam]) => ({ | ||
...acc, | ||
[queryKey]: take(store, queryParam) | ||
}), | ||
{} | ||
) | ||
}) | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,7 @@ | ||
import { walk } from './walk' | ||
|
||
const handle = (payload, key, value) => { | ||
return (payload[key] = value) | ||
} | ||
|
||
export const set = (object, key, value) => { | ||
return walk( | ||
object, | ||
key, | ||
({ payload, key: localKey, isLast, value: localValue }) => { | ||
if (!isLast && localValue === undefined) payload[localKey] = {} | ||
if (isLast) handle(payload, localKey, value) | ||
} | ||
) | ||
} | ||
export const set = (object, setKey, value) => | ||
walk(object, setKey, ({ payload, key, isLast, value: localValue }) => { | ||
if (!isLast && localValue === undefined) payload[key] = {} | ||
if (isLast) payload[key] = value | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,18 @@ | ||
import { toChain } from '../utils/path' | ||
|
||
const handle = (payload, key, cb, isLast) => { | ||
cb && cb({ payload, key, isLast, value: payload[key] }) | ||
return payload[key] | ||
} | ||
|
||
export const walk = (object, path, cb = null) => { | ||
let pathArray = toChain(path) | ||
return pathArray.reduce( | ||
(acc, key, i) => acc && handle(acc, key, cb, pathArray.length - 1 === i), | ||
(payload, key, i) => | ||
payload && | ||
(cb && | ||
cb({ | ||
payload, | ||
key, | ||
isLast: pathArray.length - 1 === i, | ||
value: payload[key] | ||
}), | ||
payload[key]), | ||
object | ||
) | ||
} |