-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(core): zip.select and assorted predicates #113
Conversation
This comment has been minimized.
This comment has been minimized.
763868c
to
1dcec7f
Compare
Pull Request Test Coverage Report for Build 420
💛 - Coveralls |
e2e6a65
to
7432584
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, look at this:
> function* four() {
... console.log('up to 1')
... yield 1
... console.log('up to 2')
... yield 2
... console.log('up to 3')
... yield 3
... console.log('over')
... }
undefined
> var x = four()
undefined
> for (var i of x) {
... console.log('got', i)
... }
up to 1
got 1
up to 2
got 2
up to 3
got 3
over
undefined
>
> var spr = [0, ...four()]
up to 1
up to 2
up to 3
over
undefined
>
In other words, we can't use [...generator()] as it eagerly realises the generator. We could modify the signature of descendants to say it returns an iterable, not an array; but we will have to handle it downstream (in select).
packages/core/src/zip/select.js
Outdated
let result = [location] | ||
for (let pred of predicates) { | ||
if (R.is(String)(pred)) { | ||
result = result.map(loc => elementChild(pred)(loc)).filter(l => !!l) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our idiomatic use of a keyPath so far has been to refer to a single child or multiple children under a key. E.g. uiFor('bla')
will render a single child under bla
or all children found there if it is an array.
We need to keep the same. Does elementChild
do that? If it does, the name is misleading.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I know you are trying to wrap your head around currying but
elementChild(pred)(loc)
Is just damn ugly. elementChild(pred, loc)
please.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have any issue wrapping my head with curring. Ugly is your conversing with me, and also commenting on outdated code (elementChild
has been childAt
for a while).
The usage is changed as you suggest. Also, I will revisit childAt
one more time, as it is the only thing that doesn't make select
generic.
Regarding this:
Our idiomatic use of a keyPath so far has been to refer to a single child or multiple children under a key. E.g. uiFor('bla') will render a single child under bla or all children found there if it is an array.
No, we don't implement childAt
like so at the moment.
🤔 ... about the following requirement:
... even though it is implemented at the moment, it might be an unnecessary complication:
Maybe we drop this requirement? |
You are right, it's a specific interpretation of some skele/app stuff. We could easily add a wrapper in skele/app of select that adds that convenience.
I'm thinking stuff like below gets very readable
```javascript
// this
select('tabs', selectedTab, 'content', ['quote'])'
// vs
select(childrenAt('tabs'), selectedTab, childrenAt('content'), isOfKind('quote'))
const selectedTab = t => t.get('selected') === true
```
Aslo, in my eyes `childAt` and `childrenAt` are somehow still the same fn.
On Jan 7, 2019, at 21:33, Andon Sikavica <notifications@github.com<mailto:notifications@github.com>> wrote:
🤔 ... about the following requirement:
* 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
... even though it is implemented at the moment, it might be an unnecessary complication:
* The first requirement, descending into a property is not generic. We have two options there, to use the current childAt motion (an implementation that is not clear at the moment), or to use the childrenAt selector. Both of them are "skele" specific. select on the other hand, is generic.
* The second requirement, to use an array of strings, might not be better than just writing ofKind predicate. This is especially noticeable when both string (descending) and string-array (of-kind) are used together. You really need to think/know what the syntax means.
Maybe we drop this requirement?
@ognen<https://github.com/ognen> What do you think?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub<#113 (comment)>, or mute the thread<https://github.com/notifications/unsubscribe-auth/AAC_V3qMaUYwyo66S5LjKmYwEbbMxeB_ks5vA68bgaJpZM4WM0ye>.
|
@ognen okey, I left it be as it is. I also left I deleted the motion Will merge it, unless there are some more comments. |
Implements the function
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:
ofKind
Also implements the functions that can me used in the
select
function, in some of the following categories:ancestors
an iterable of the location's ancestors; nearest parent firstdescendants
, an iterable of all descendants, depth-first, right-to-leftchildren
an iterable of the location's childrenchildrenAt(key)
an iterable of the location's children for the specified keyofKind(kind)
a predicate function which will return true if the location points to an element the given kindCloses #53