Conversation
test/unit/initialize.test.js
Outdated
it('allows for deep multi dimensional refs', async function () { | ||
let component = { | ||
render () { | ||
return <div ref='divs[test[first]]'>hello</div> |
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.
This looks counterintuitive. I would expect divs[first][second]
, not this.
Now you mention it it does look better your way.
Will update the pr when I get chance.
…On 3 Apr 2017 8:28 p.m., "Nikolay Yakimov" ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In test/unit/initialize.test.js
<#50 (comment)>:
> + update () {}
+ }
+
+ etch.initialize(component)
+
+ expect('divs[first]' in component.refs).to.be.false
+ expect('divs' in component.refs).to.be.true
+ expect(component.refs.divs).to.have.all.keys(['first', 'second'])
+ expect(component.refs.divs.second.textContent).to.equal('second')
+
+ })
+
+ it('allows for deep multi dimensional refs', async function () {
+ let component = {
+ render () {
+ return <div ref='divs[test[first]]'>hello</div>
This looks counterintuitive. I would expect divs[first][second], not this.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#50 (review)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AABMmVgxO1M01sgMHPO1SGhPbuqdsJ7nks5rsUhLgaJpZM4Mx9s2>
.
|
As suggested sub keys are now defined as |
I'm working on maintaining backwards compatibility at the moment. It needs a flag to enable this new feature (then next release inverted to disable it). This is so that refs matching |
This is a cool idea that I considered as well in the past, but I'm somewhat reluctant to bring on this extra complexity. I want to keep Etch as simple and focused as possible... @maxbrunsfeld, @as-cii Do you have any thoughts on this? I do see the potential value of this feature. Also, if we were to decide to add this, one thought is that it might make more sense to use a totally different prop name rather than the
|
@nathansobo All names etc... can be changed to better conform with standards, I was focusing on getting it working first. Using
|
I've updated the PR to use arrays in the ref option to use a multi-dimensional ref.
|
@nathansobo I'm pretty happy with how this works now. I didn't split the functionality into another property for 2 reasons.
Let me know if there is anything that needs adding/correcting. |
@@ -65,4 +65,60 @@ describe('etch.initialize(component)', () => { | |||
etch.initialize(component) | |||
}).to.throw(/invalid falsy value/) | |||
}) | |||
|
|||
it('allows for multi dimensional refs', async function () { |
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.
Forgive me if I'm missing it, but do you have a test for the removal case. I'm specifically concerned about the logic for removing sub-object when all refs at a given level of nesting disappear.
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.
You're right. Written a test for moving components around within refs and there were a couple of bugs with how buildRefs.clear
works and with my edits to updateRefs
.
I've fixed them now and added it to this PR.
@nathansobo any news on this PR? |
I've been on the fence about adding the complexity. @maxbrunsfeld can you help me think about whether we should merge this. I'm leaning yes. |
@nathansobo ISTM that if you need nested refs you probably should just use sub components. I agree with your concern re: complexity. |
Yeah, that's the approach I've taken previously. My main concern is that if this breaks I'll have to take time away from improving Atom to deal with it. I'd be curious to hear more use cases. |
Yeah, I don't have a strong opinion, but I'm inclined to agree with @larkin and the concerns about whether the complexity is worth it. |
Well, one use-case when this could be handy (although only one-dimensionally) is when you have a |
@lierdakil You could create a subcomponent for each item and register it in a map that you pass in as a prop manually. That's what I've done in the past though it is a bit more boilerplate than this would be. |
After discussing this, @BinaryMuse pointed out that React allows a function to be provided as the value of the |
IIRC, automatic |
Allows refs to be multi-dimensional
can be accessed with
component.refs.selection.foo
andcomponent.refs.selection.bar
.Can go as deep as you want.