-
Notifications
You must be signed in to change notification settings - Fork 396
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
Comments
@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 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. |
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 :) |
+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 |
I've been heavily relying on var info = Ractive.getNodeInfo(node)
// { ractive: ractive, keypath: keypath, index: index } |
👍 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) |
Expose DOM nodeRactive info in public API - RFC
@Crisfole @emiltamas Just to clarify, there's now a static method (if you're using the edge build called |
Awesome, thanks so much. I've been following this thread so I'm already aware of the good news! |
👍 Way to go! :) |
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?
The text was updated successfully, but these errors were encountered: