You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We need a way to select one or more elements in the application state given a starting location; also we need a way to specify such a selector to be used in ways we use CSS selectors or xpath queries.
// A tab navigation element containing a list of scenes, of which only one can be active at a time {'kind': 'tab-navigation','@@girders-elements/children': 'scenes','scenes': [{kind: 'scene',id: 1,active: true},{kind: 'scene',id: 2}]}// essentially, dispatching 'select' with sceneId = someId on 'tab-navigation' will deactivate all scenes except the selected oneupdates.register(['tab-navigation'],nav=>{// thread the 'select' action to all children of kind scene where the id is not the sceneId from the actionnav.thread('select',action=>select(children,kindOf('scene'),not(propEq('id',action.sceneId)),'deactivate');// thread the same action to all children of kind scene where action.sceneId === id nav.thread('select',action=>select(children,kindOf('scene'),propEq('id',action.sceneId)))),'activate');}// finally the receiving actionsupdate.register('scene',scene=>{scene.register('deactivate',s=>s.set('active',false));scene.register('activate',s=>s.set('active',true));});
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
We need a way to select one or more elements in the application state given a starting location; also we need a way to specify such a selector to be used in ways we use CSS selectors or xpath queries.
The trick clojure.data.xml is using is well suited here.
and place in
src/zip/index.js
The function is in curried form. It expects a variable arg-set of predicates that is used to select/filter starting from the current location.
Each predicate can be:
ofKind
The system should be identical to the one in clojure.
In addition to the select function, a set of built-in predicates need to be provided:
ancestors
a list of the location's ancestors; nearest parent firstdescendants
, a list of all descendants, depth-first, right-to-leftchildren(collection)
returns a list of the location's children. if acollection
is provided it will list only the children in that collectionofKind(kind)
a predicate function which will return true if the location points to an element the given kindThe text was updated successfully, but these errors were encountered: