-
-
Notifications
You must be signed in to change notification settings - Fork 923
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
Remove m.prop
+ m.withAttr
#2317
Conversation
@@ -365,8 +365,14 @@ var Login = { | |||
login: function() {/*...*/}, | |||
view: function() { | |||
return m(".login", [ | |||
m("input[type=text]", {oninput: m.withAttr("value", this.setUsername.bind(this)), value: this.username}), | |||
m("input[type=password]", {oninput: m.withAttr("value", this.setPassword.bind(this)), value: this.password}), |
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.
Good grief, what a mess this was. A large part of the beauty of closures by default will be removing all these horrid custom component methods and this
references.
@@ -383,7 +383,10 @@ var Form = { | |||
}, | |||
view: function() { | |||
return m("form", [ | |||
m("input[placeholder='Search']", {oninput: m.withAttr("value", function(v) {state.term = v}), value: state.term}), |
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.
Mind-boggling this was seen as useful at the time.
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.
100%
e2cb189
to
a02a910
Compare
- For many uses, `m.withAttr` is *more* verbose than just directly using an event handler - If you're using it with a bound callback, you're literally wasting a single character in the human readable version (and you're *saving* them in the minified output). - It sometimes obscures your intent, if overused. - Functions are easier to compress than `m.withAttr`, resulting in slightly smaller bundles. - `m.withAttr` is overused anyways. - `m.prop` is basically useless without `m.withAttr`, and the API doesn't have the same benefits it had with 0.2.x.
Description
m.withAttr
is more verbose than just directly using an event handlerm.withAttr
, resulting in slightly smaller bundles.m.withAttr
is overused anyways.m.prop
is basically useless withoutm.withAttr
, and the API doesn't have the same benefits it had with 0.2.x.See the corresponding docs changes to see what I mean.
Motivation and Context
Spawned from a Gitter conversation starting approximately here (and continued for a few hours). Also, look at the changes to the docs, and that should also show why I'd like to make the change.
How Has This Been Tested?
Ran
npm test
and everything worked as usual. The linter errors are unrelated.Types of changes
Checklist:
docs/change-log.md