-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Idea: bind actions automatically in MobX 3 #699
Comments
-1, binding methods to instance is completely unrelated to action purpose. |
I agree with Andy. mobx-utils could have something like boundAction?
…On Wed, Dec 7, 2016 at 3:12 PM, Andy Kogut ***@***.***> wrote:
-1, binding methods to instance is completely unrelated to action purpose.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#699 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAIrcoOBRPBXtOBfcZ4ZmnGyl18zYpAEks5rFyFJgaJpZM4LG-eS>
.
--
-Matt Ruby-
[email protected]
|
There was similar discussion in the React team as I recall (about how createClass auto bound, but Component didn't). The reason they went against it is basically the reason @andykog stated; it would amount to extra magic which, though well intentioned would only really confuse beginners in the long run as it isn't something other parts of ES6 do, though you may expect it to. |
I don't use decorators, so my constructors are cluttered with: |
I like the idea of |
I'm using somewhere in my code the fact that JS methods (and actions too) aren't bound to copy an object method from an object to an another and have the method work on the object it is attached too. Something like: const obj1 = observable({prop: 1});
obj1.set = action(function() { this.prop = 2 });
const obj2 = observable(toJS(obj1));
// Now I have the expected behaviour of :
obj1.set() // ==> obj1.prop = 2
obj2.set() // ==> obj2.prop = 2 This is how Javascript works and |
Closing this issue as [email protected] is now available, which addresses this issue. Changelog: https://github.com/mobxjs/mobx/blob/mobx3/CHANGELOG.md#300. The changes in more details: https://github.com/mobxjs/mobx/pull/725/files. Feel free to re-open if questions arise! Use |
action
could automatically apply "autobinding" in many cases, similarly how@autobind
orReact.createClass
do this. I think this could help beginning programmers to make less mistakes.Disadvantage is that this is more memory consuming when using classes / prototypes. Class methods are normally stored only on the prototype, but need to be stored on instances to achieve binding.
The text was updated successfully, but these errors were encountered: