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

Decorators Accessing Privates #1217

Closed
Crisfole opened this issue Sep 16, 2014 · 8 comments · Fixed by #1509
Closed

Decorators Accessing Privates #1217

Crisfole opened this issue Sep 16, 2014 · 8 comments · Fixed by #1509

Comments

@Crisfole
Copy link

Several of the example decorators I've found directly access node._ractive.

This might be a question rather than an issue, but it seems dirty to be directly accessing things marked private (which I generally assume might change at any release) in plugin code.

Is this a good practice? (See the select2 decorator and this demo, linked from the issues for two examples).

If it's good practice could it be documented somewhere visibly? If not, it seems clear that accessing a node's ractive is important, especially for decorators. Could a public method be added for accessing that without messing around with internals?

@martypdx
Copy link
Contributor

@Crisfole I was just thinking about this last week. I've seen two uses so far: 1) getting to the keypath, or context, of the node (the select2 decorator) and 2) getting the ractive "owner" of an arbitrary node, like in a drag and drop situation.

At a simple level, we could add a method like Ractive.getNodeInfo(node) that at least abstracted the implementation of where that information was being stored.

IMO, it would also be worthwhile to consider whether we could eliminate the need to do this. For example, if decorators received all of that information, node, keypath, context, index(es), as the first argument.

@Crisfole
Copy link
Author

That makes sense to me. Just figured I'd mention that it felt a little icky as I'm just getting started w/ Ractive. My aversion to messing with javascript variables that start with _ is pretty strong :)

@Rich-Harris
Copy link
Member

+1. It's not uncommon for a decorator to need to access information about the current instance, or its environment - there should be an API for this that's documented and tested. Using node._ractive is a filthy hack! Mea culpa.

@martypdx
Copy link
Contributor

I've been heavily relying on node._ractive lately. Would a good start be a static method?

var info = Ractive.getNodeInfo(node)
// { ractive: ractive, keypath: keypath, index: index }

@emiltamas
Copy link
Contributor

👍 I have multiple views managed by the same controller. The events handlers are bound (via bind) to the controller instance so I'm losing the ractive instance reference (unless I resort to _ractive), resulting in a more complicated code overall (e.g. this.currentView = RactiveInstance)

evs-chris added a commit to evs-chris/ractive that referenced this issue Nov 29, 2014
Rich-Harris added a commit that referenced this issue Nov 29, 2014
Expose DOM nodeRactive info in public API - RFC
@Rich-Harris
Copy link
Member

@Crisfole @emiltamas Just to clarify, there's now a static method (if you're using the edge build called Ractive.getNodeInfo() - demo here

@emiltamas
Copy link
Contributor

Awesome, thanks so much. I've been following this thread so I'm already aware of the good news!

@Crisfole
Copy link
Author

👍 Way to go! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants