Skip to content

Commit 6a96433

Browse files
committed
Mention the update method of decorators
1 parent 85a434d commit 6a96433

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

docs/0.8/Writing decorator plugins.md.hbs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,22 @@ Firstly, we need to add the `decorator` *directive* to any nodes that the decora
1616

1717
Now, the `tooltip` decorator function will be called when the `<span>` is added to the DOM. The first argument to the function is the `<span>` itself; subsequent arguments given after the `:` in the directive will be passed to the function - in this case, there will be a second argument, which is the 'This is a tooltip' message.
1818

19-
Within that function, we can do whatever we like - the only rule is that it must return an object with a `teardown()` method that gets called if the `<span>` is removed from the DOM:
19+
Within that function, we can do whatever we like - the only rule is that it must return an object with a `teardown()` method that gets called if the `<span>` is removed from the DOM. An optional `update()` method can also be returned, which accepts the updated arguments provided to the decorator.
20+
21+
Whenever the arguments provided to the decorator update, one of two things can happen:
22+
23+
- If the `update` method IS NOT provided, the `teardown()` method is called and the decorator function is re-run.
24+
25+
- If the `update()` method IS provided, it is called instead of tearing down and setting the decorator back up.
2026

2127
```js
2228
var tooltipDecorator = function ( node, content ) {
2329
// setup work goes here...
2430

2531
return {
32+
update: function( ...args ){
33+
// ...code that runs on args update
34+
},
2635
teardown: function () {
2736
// ...any cleanup work goes here
2837
}

docs/edge/Writing decorator plugins.md.hbs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,22 @@ Firstly, we need to add the `decorator` *directive* to any nodes that the decora
1616

1717
Now, the `tooltip` decorator function will be called when the `<span>` is added to the DOM. The first argument to the function is the `<span>` itself; subsequent arguments given after the `:` in the directive will be passed to the function - in this case, there will be a second argument, which is the 'This is a tooltip' message.
1818

19-
Within that function, we can do whatever we like - the only rule is that it must return an object with a `teardown()` method that gets called if the `<span>` is removed from the DOM:
19+
Within that function, we can do whatever we like - the only rule is that it must return an object with a `teardown()` method that gets called if the `<span>` is removed from the DOM. An optional `update()` method can also be returned, which accepts the updated arguments provided to the decorator.
20+
21+
Whenever the arguments provided to the decorator update, one of two things can happen:
22+
23+
- If the `update` method IS NOT provided, the `teardown()` method is called and the decorator function is re-run.
24+
25+
- If the `update()` method IS provided, it is called instead of tearing down and setting the decorator back up.
2026

2127
```js
2228
var tooltipDecorator = function ( node, content ) {
2329
// setup work goes here...
2430

2531
return {
32+
update: function( ...args ){
33+
// ...code that runs on args update
34+
},
2635
teardown: function () {
2736
// ...any cleanup work goes here
2837
}

0 commit comments

Comments
 (0)