Skip to content
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

abstract-select: selectedIndexes accessor is missing #1296

Closed
NV opened this issue Sep 12, 2013 · 17 comments
Closed

abstract-select: selectedIndexes accessor is missing #1296

NV opened this issue Sep 12, 2013 · 17 comments

Comments

@NV
Copy link
Collaborator

NV commented Sep 12, 2013

abstract-select.js doesn’t have anything like selectedIndexes accessor from native’s select. Should it be implemented?

@aadsm
Copy link
Collaborator

aadsm commented Sep 12, 2013

I believe there's no need for it because it is backed up by a range-controller and all that info can be found there.

@NV
Copy link
Collaborator Author

NV commented Sep 12, 2013

Thanks for pointing out. However, I still couldn’t find selectedIndexes in the range-controller.

selection method has an array of items (e.g. [{label:"en", value:"English"}]) which is not quite what I want.
visibleIndexes is null.

@kriskowal
Copy link
Member

@NV what value are you expecting?

@NV
Copy link
Collaborator Author

NV commented Sep 12, 2013

Numeric value, which is the index of the selected item(s). When the first item selected I expect to get 0.

@kriskowal
Copy link
Member

rangeController.iterations.filter{selected}.map{index} with an optional .only() at the end for the single selection case.

@kriskowal
Copy link
Member

@NV strike that. That might not work anymore. You might have to do rangeController.orgnaizedContent.enumerate().filter{^selection.has(.1)}.map{.0}.

@NV
Copy link
Collaborator Author

NV commented Sep 12, 2013

@kriskowal
There is a typo in orgnaizedContent. It doesn’t throw any errors, just silently return empty array. Not very debug-friendly.

It still returns empty array, I’m trying to understand why. Could you explain .filter{^selection.has(.1)} part? Particularly, what’s ^selection?

@NV
Copy link
Collaborator Author

NV commented Sep 12, 2013

^ is some sort of a parent operator. It checks contentController.selection. But what’s .1?

@kriskowal
Copy link
Member

^ is the parent scope operator. the .operator{block} blocks create a nested scope, so you need to go up one to get back to your source object. .1 is equivalent to this.1 or this[1] and is an artifact of the fact that although a gets parsed as a property, 1 gets parsed as a number literal, but both .a and .1 get parsed as properties of the implied this. With most FRB operators, it is safe to use an implied this for any operand, e.g., odds <- numbers.filter{!%2} means !(this % 2). It is however unsafe to use an implied operand for + because of unary +, and there’s a pretty strong case for removing the implied this in most cases, so perhaps you should stick with this[0] and this[1].

@kriskowal
Copy link
Member

To be clear in both JavaScript, with Collections loaded, and in FRB ['a', 'b', 'c'].enumerate() renders to [[0, 'a'], [1, 'b'], [2, 'c']].

@NV
Copy link
Collaborator Author

NV commented Sep 12, 2013

@kriskowal thanks for the explanation.

@kriskowal
Copy link
Member

Pardon:

rangeController.orgnaizedContent.enumerate().filter{^rangeController.selection.has(this[1])}.map{this[0]}

selection is a property of the rangeController, an array of all the selected values from rangeController.content. rangeController.organizedContent is the input side for a Repetition, and is just content passed through various adapters for optional filtering, optional sorting, and Flow frustum culling with the rangeController.visibleIndexes, if any of those are provided. For the purposes of a <select> component, none of those are in use.

@NV
Copy link
Collaborator Author

NV commented Sep 12, 2013

I’d like to disqus: do we really need selectedIndexes at all? We already selected values:

"values": {
    "<->": "contentController.selection"
},
"value": {
    "<->": "values.0"
},

Shouldn’t it be sufficient? Off the top of my head I couldn’t think of a real-world example.

@aadsm
Copy link
Collaborator

aadsm commented Sep 13, 2013

I agree that we don't need it.
If someone finds a use for it in the future he can always use FRB to create it.

@kriskowal
Copy link
Member

I agree with @aadsm.

A note that values.only() is more powerful than values.0 because it will be defined only when values.length == 0, and because of the two way binding, setting value would clear out all other values.

@NV
Copy link
Collaborator Author

NV commented Sep 13, 2013

Okay, I’ll just rebaseline the tests for montagejs/matte#27 then. Thanks.

@NV
Copy link
Collaborator Author

NV commented Nov 15, 2013

Closing as a FRB workaround had been mentioned above.

@NV NV closed this as completed Nov 15, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants