@matchlighter/common_library
Advanced tools
Comparing version 1.2.2 to 1.2.3
declare const syncedObservableSymbol: unique symbol; | ||
declare type FilterFunc = (path: string, object: any) => boolean; | ||
declare type FilterSelector = string | string[] | FilterFunc; | ||
export interface SyncedObservableOptions { | ||
@@ -8,3 +10,3 @@ /** | ||
*/ | ||
refs?: string[]; | ||
refs?: FilterSelector; | ||
/** | ||
@@ -15,3 +17,3 @@ * Accepts a list of JSONPath patterns. | ||
*/ | ||
exclude?: string[]; | ||
exclude?: FilterSelector; | ||
} | ||
@@ -18,0 +20,0 @@ declare class SyncedObservable<T> { |
@@ -66,4 +66,4 @@ import { observable } from 'mobx'; | ||
deepSyncInternal(target, obj, { | ||
refPaths: buildPathSets(obj, options.refs), | ||
excludePaths: buildPathSets(obj, options.exclude), | ||
refPaths: normalizeFilter(options.refs, obj), | ||
excludePaths: normalizeFilter(options.exclude, obj), | ||
currentPath: ['$'], | ||
@@ -77,5 +77,5 @@ }); | ||
const currentPathSpec = JSONPath.stringify(currentPath); | ||
if (options.excludePaths.has(currentPathSpec)) | ||
if (options.excludePaths(currentPathSpec, v)) | ||
continue; | ||
if (options.refPaths.has(currentPathSpec) || typeof v != 'object') { | ||
if (options.refPaths(currentPathSpec, v) || typeof v != 'object') { | ||
target[k] = v; | ||
@@ -109,2 +109,10 @@ } | ||
} | ||
function normalizeFilter(spec, obj) { | ||
if (typeof spec == 'function') | ||
return spec; | ||
if (typeof spec == 'string') | ||
spec = [spec]; | ||
const pathset = buildPathSets(obj, spec); | ||
return (path, obj) => pathset.has(path); | ||
} | ||
function buildPathSets(obj, paths) { | ||
@@ -111,0 +119,0 @@ const pathSet = new Set(); |
{ | ||
"name": "@matchlighter/common_library", | ||
"version": "1.2.2", | ||
"version": "1.2.3", | ||
"description": "Shared Functions, Helpers, Patterns & Utilities for Apps and Libraries", | ||
@@ -26,3 +26,3 @@ "author": "Matchlighter", | ||
"test": "jest", | ||
"build": "tsc", | ||
"build": "node ./scripts/clean_build.js && tsc", | ||
"prepublishOnly": "npm run-script build" | ||
@@ -47,2 +47,3 @@ }, | ||
"@types/react": "^16.9.2", | ||
"fs-extra": "^8.1.0", | ||
"jest": "^24.9.0", | ||
@@ -49,0 +50,0 @@ "jsonpath": "^1.0.2", |
Sorry, the diff of this file is not supported yet
97174
1513
15