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

@isiahmeadows
Copy link
Member

@isiahmeadows isiahmeadows 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
@isiahmeadows isiahmeadows self-assigned this Nov 29, 2018
@project-bot project-bot bot added this to Needs triage in Triage/bugs Nov 29, 2018
@isiahmeadows isiahmeadows added this to Under consideration in Feature requests/Suggestions via automation Nov 29, 2018
@isiahmeadows isiahmeadows removed this from Needs triage in Triage/bugs 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}),

This comment has been minimized.

@barneycarroll

barneycarroll Nov 29, 2018
Member

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}),

This comment has been minimized.

@barneycarroll

barneycarroll Nov 29, 2018
Member

Mind-boggling this was seen as useful at the time.

Feature requests/Suggestions automation moved this from Under consideration to Planned/In Progress Nov 29, 2018
Copy link
Member

@barneycarroll barneycarroll left a comment

100%

@isiahmeadows isiahmeadows force-pushed the isiahmeadows:remove-utils branch 2 times, most recently from e2cb189 to a02a910 Nov 30, 2018
- 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.
@isiahmeadows isiahmeadows merged commit 26b8d99 into MithrilJS:next Dec 1, 2018
1 check passed
1 check passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
Feature requests/Suggestions automation moved this from Planned/In Progress to Completed/Declined Dec 1, 2018
@isiahmeadows isiahmeadows deleted the isiahmeadows:remove-utils branch Dec 1, 2018
defic added a commit to defic/ws-examples that referenced this pull request Aug 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants