-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): zip.select and assorted predicates (#113)
Implements the function const select: (...arguments) => location => Iterable<locations> The function is in curried form. It expects a variable arg-set that is used to select/filter starting from the current location. Each argument can be: - a 'string' which is interpreted as descending into a property. The property should have an element (or child elements) - an array of strings which is interpreted as the predicate `ofKind` - a function returning a list of locations (selector or motion function) - a predicate function used to filter out nodes Also implements the functions that can me used in the `select` function, in some of the following categories: - selectors - `ancestors` an iterable of the location's ancestors; nearest parent first - `descendants`, an iterable of all descendants, depth-first, right-to-left - `children` an iterable of the location's children - `childrenAt(key)` an iterable of the location's children for the specified key - predicates - `ofKind(kind)` a predicate function which will return true if the location points to an element the given kind Closes #53
- Loading branch information
Showing
11 changed files
with
820 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
'use strict' | ||
|
||
import I from 'immutable' | ||
|
||
import * as zip from '../' | ||
import { childrenProperty, flow } from '../../data' | ||
|
||
import { propEq } from '../predicate' | ||
|
||
const zipper = data => zip.elementZipper({})(data) | ||
|
||
const data = { | ||
kind: ['navigation', 'tabs'], | ||
[childrenProperty]: ['tabs', 'settings'], | ||
title: 'App', | ||
tabs: [ | ||
{ | ||
kind: ['tab'], | ||
title: 'Murder Bot', | ||
}, | ||
{ | ||
kind: ['tab'], | ||
title: 'Dr Mensah', | ||
[childrenProperty]: ['elements', 'deeplink'], | ||
elements: [ | ||
{ | ||
kind: ['element'], | ||
title: 'robot', | ||
}, | ||
{ | ||
kind: ['element'], | ||
title: 'human', | ||
}, | ||
], | ||
deeplink: { | ||
kind: ['link'], | ||
title: 'goodreads', | ||
}, | ||
}, | ||
], | ||
settings: { | ||
kind: ['settings'], | ||
title: 'Martha Wells', | ||
}, | ||
} | ||
|
||
describe('zipper predicates', () => { | ||
test('propEq', () => { | ||
const root = zipper(I.fromJS(data)) | ||
expect( | ||
flow( | ||
root, | ||
propEq( | ||
'settings', | ||
I.fromJS({ kind: ['settings'], title: 'Martha Wells' }) | ||
) | ||
) | ||
).toBeTruthy() | ||
}) | ||
}) |
Oops, something went wrong.