Skip to content

Commit aa443f0

Browse files
authored
Merge pull request #28 from pzuraq/remove-template-transform
[REFACTOR] Remove template transform
2 parents cfab68e + e0f9e2a commit aa443f0

File tree

8 files changed

+21
-112
lines changed

8 files changed

+21
-112
lines changed

README.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ A better `mut` helper!
55
```hbs
66
{{this.greeting}}
77
8-
<button {{on "click" (set this.greeting "Hello!")}}>
8+
<button {{on "click" (set this "greeting" "Hello!")}}>
99
English
1010
</button>
1111
12-
<button {{on "click" (fn (set this.greeting) "Hola!")}}>
12+
<button {{on "click" (fn (set this "greeting") "Hola!")}}>
1313
Español
1414
</button>
1515
```
@@ -22,7 +22,7 @@ without having to write your own custom action. For simple cases, this is pretty
2222
handy:
2323

2424
```hbs
25-
<button {{on "click" (set this.greeting "Hello!")}}>
25+
<button {{on "click" (set this "greeting" "Hello!")}}>
2626
English
2727
</button>
2828
```
@@ -61,7 +61,7 @@ export default class Counter extends Component {
6161

6262
```hbs
6363
<!-- usage -->
64-
<Counter @onClick={{set this.currentCount}} />
64+
<Counter @onClick={{set this "currentCount"}} />
6565
```
6666

6767
This will set the value of `this.currentCount` to whatever value is passed to it
@@ -70,10 +70,10 @@ user clicks the button).
7070

7171
### Passing a dynamic path
7272

73-
You can pass a path dynamically using the `path` named argument to the helper:
73+
You can pass a path dynamically using to the helper as well:
7474

7575
```hbs
76-
<button {{on "click" (set this "Hello!" path=this.greetingPath)}}>
76+
<button {{on "click" (set this this.greetingPath "Hello!")}}>
7777
English
7878
</button>
7979
```
@@ -92,13 +92,13 @@ from [ember-composable-helpers](https://github.com/DockYard/ember-composable-hel
9292
to first pick the value off of the event, and then pass it to `{{set}}`:
9393

9494
```hbs
95-
<input {{on "input" (pick "target.value" (set this.value))}}>
95+
<input {{on "input" (pick "target.value" (set this "value"))}}>
9696
```
9797

9898
### Differences from `mut`
9999

100-
- No need to call wrap the helper (e.g. `(set this.foo)` === `(fn (mut this.foo))`)
101-
- Optional last parameter if setting a static value (e.g. `(set this.foo "bar")` === `(fn (mut this.foo) "bar")`)
100+
- No need to call wrap the helper (e.g. `(set this "foo")` === `(fn (mut this.foo))`)
101+
- Optional last parameter if setting a static value (e.g. `(set this "foo" "bar")` === `(fn (mut this.foo) "bar")`)
102102
- Cannot be used as both a getter and setter for the value, only provides a setter
103103

104104
## Compatibility

addon/helpers/set.js

+2-12
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,8 @@ import { helper } from '@ember/component/helper';
22
import { assert } from '@ember/debug';
33
import { set as emberSet } from '@ember/object';
44

5-
function set(positional, named) {
6-
let [target, maybePath, maybeValue] = positional;
7-
8-
let namedPath = named.path;
9-
10-
let path;
11-
12-
if (namedPath !== undefined) {
13-
path = maybePath !== undefined && maybePath !== '' ? `${maybePath}.${namedPath}` : namedPath;
14-
} else {
15-
path = maybePath;
16-
}
5+
function set(positional) {
6+
let [target, path, maybeValue] = positional;
177

188
assert(
199
'you must pass a path to {{set}}. You can pass a path statically, as in `{{set this.foo}}`, or with the path argument dynamically, as in `{{set this path="foo"}}`',

index.js

-24
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,4 @@
22

33
module.exports = {
44
name: require('./package').name,
5-
6-
setupPreprocessorRegistry(type, registry) {
7-
const plugin = this._buildPlugin();
8-
9-
plugin.parallelBabel = {
10-
requireFile: __filename,
11-
buildUsing: '_buildPlugin',
12-
params: {}
13-
};
14-
15-
registry.add('htmlbars-ast-plugin', plugin);
16-
},
17-
18-
_buildPlugin() {
19-
const SetTransform = require('./lib/set-transform');
20-
21-
return {
22-
name: 'set-transform',
23-
plugin: SetTransform,
24-
baseDir() {
25-
return __dirname;
26-
}
27-
};
28-
}
295
};

lib/set-transform.js

-57
This file was deleted.

tests/dummy/app/templates/application.hbs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
</div>
44

55
<div>
6-
<button type="button" {{on "click" (set this.greeting "Hello!")}}>
6+
<button type="button" {{on "click" (set this "greeting" "Hello!")}}>
77
English
88
</button>
99
</div>
@@ -14,7 +14,7 @@
1414
count: {{this.count}}
1515
</div>
1616
<div>
17-
<Counter @onUpdate={{set this.count}} />
17+
<Counter @onUpdate={{set this "count"}} />
1818
</div>
1919

2020
<hr>
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<Child @onChange={{set @user.name}} />
1+
<Child @onChange={{set @user "name"}} />
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
<button type="button" {{on "click" (set @parameter 42 path=@path)}}>
1+
<button type="button" {{on "click" (set @parameter @path 42)}}>
22
Update
33
</button>

tests/integration/helpers/set-test.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module('Integration | Helper | set', function(hooks) {
1111
await render(hbs`
1212
<span data-test-greeting>{{this.greeting}}</span>
1313
14-
<button type="button" {{on "click" (set this.greeting "Hello!")}}>
14+
<button type="button" {{on "click" (set this "greeting" "Hello!")}}>
1515
English
1616
</button>
1717
`);
@@ -30,7 +30,7 @@ module('Integration | Helper | set', function(hooks) {
3030
<span data-test-greeting>{{this.person.name}}</span>
3131
3232
{{#let this.person as |person|}}
33-
<button type="button" {{on "click" (set person.name "Liz")}}>
33+
<button type="button" {{on "click" (set person "name" "Liz")}}>
3434
Set Name
3535
</button>
3636
{{/let}}
@@ -50,7 +50,7 @@ module('Integration | Helper | set', function(hooks) {
5050
<span data-test-greeting1>{{this.greeting1}}</span>
5151
<span data-test-greeting2>{{this.greeting2}}</span>
5252
53-
<button type="button" {{on "click" (set this "Hello!" path=this.path)}}>
53+
<button type="button" {{on "click" (set this this.path "Hello!")}}>
5454
Set Greeting
5555
</button>
5656
`);
@@ -75,7 +75,7 @@ module('Integration | Helper | set', function(hooks) {
7575
<span data-test-greeting1>{{this.obj.greeting1}}</span>
7676
<span data-test-greeting2>{{this.obj.greeting2}}</span>
7777
78-
<button type="button" {{on "click" (set this.obj "Hello!" path=this.path)}}>
78+
<button type="button" {{on "click" (set this (concat "obj." this.path) "Hello!")}}>
7979
Set Greeting
8080
</button>
8181
`);
@@ -114,7 +114,7 @@ module('Integration | Helper | set', function(hooks) {
114114
test('it works without a value', async function(assert) {
115115
await render(hbs`
116116
<span data-test-count>{{this.count}}</span>
117-
<Counter @onUpdate={{set this.count}} />
117+
<Counter @onUpdate={{set this "count"}} />
118118
`);
119119

120120
assert.equal(find('[data-test-count]').textContent.trim(), '');
@@ -143,7 +143,7 @@ module('Integration | Helper | set', function(hooks) {
143143
await render(hbs`
144144
<span data-test-greeting>{{this.greeting}}</span>
145145
146-
<input {{on "input" (pick "target.value" (set this.greeting))}}>
146+
<input {{on "input" (pick "target.value" (set this "greeting"))}}>
147147
`);
148148

149149
assert.equal(find('[data-test-greeting]').textContent.trim(), '');

0 commit comments

Comments
 (0)