-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d8de476
commit 3f4a0ce
Showing
13 changed files
with
172 additions
and
17 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
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import get from 'lodash.get'; | ||
|
||
export type Observer = { | ||
subtree: string; | ||
path: string; | ||
callback: any; | ||
depth: number; | ||
}; | ||
|
||
export const createPostObserveMiddleware = (callbacks: Array<() => void>) => { | ||
return (store: any) => (next: any) => (action: any) => { | ||
const result = next(action); | ||
|
||
callbacks.forEach((cb, index) => { | ||
cb(); | ||
}); | ||
|
||
callbacks.length = 0; | ||
|
||
return result; | ||
}; | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export type Watch = ( | ||
path: string, | ||
depth?: number, | ||
firstWatch?: boolean | ||
) => void; | ||
|
||
export type ComputeCallback = ( | ||
getValue: (path: string, depth?: number, firstRun?: boolean) => any, | ||
change: any | ||
) => any; |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function escapeSlashes(str: string | number) { | ||
return String(str).replaceAll('/', '\\/'); | ||
} |
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,8 +1,9 @@ | ||
import { SyncStatePath } from '../index'; | ||
import escapeSlashes from './escapeSlashes'; | ||
|
||
export default function immerPathToJsonPatchPath(path: SyncStatePath) { | ||
if (path.length === 0) { | ||
return ''; | ||
} | ||
return '/' + path.join('/'); | ||
return '/' + path.map(p => escapeSlashes(p)).join('/'); | ||
} |
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,8 +1,13 @@ | ||
import unescapeSlashes from './unescapeSlashes'; | ||
|
||
export default function jsonPatchPathToImmerPath(path: string) { | ||
if (!path) { | ||
return []; | ||
} | ||
|
||
path = path.replaceAll('\\/', ':::'); | ||
|
||
const immerPath = path.split('/'); | ||
immerPath.shift(); | ||
return immerPath; | ||
return immerPath.map(p => p.replaceAll(':::', '/')); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function unescapeSlashes(str: string | number) { | ||
return String(str).replaceAll('\\/', '/'); | ||
} |