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

Remove m.prop + m.withAttr #2317

Merged
merged 2 commits into from
Dec 1, 2018
Merged

Conversation

dead-claudia
Copy link
Member

@dead-claudia dead-claudia commented Nov 29, 2018

Description

  • 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.

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

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation change

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • I have updated docs/change-log.md

@dead-claudia dead-claudia added Type: Breaking Change For any feature request or suggestion that could reasonably break existing code Type: Enhancement For any feature request or suggestion that isn't a bug fix labels Nov 29, 2018
@dead-claudia dead-claudia self-assigned this Nov 29, 2018
@@ -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}),
Copy link
Member

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}),
Copy link
Member

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.

Copy link
Member

@barneycarroll barneycarroll left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

100%

@dead-claudia dead-claudia force-pushed the remove-utils branch 2 times, most recently from e2cb189 to a02a910 Compare November 30, 2018 09:33
- 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Breaking Change For any feature request or suggestion that could reasonably break existing code Type: Enhancement For any feature request or suggestion that isn't a bug fix
Projects
Status: Completed/Declined
Development

Successfully merging this pull request may close these issues.

2 participants