Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'jccazeaux-remove-functions-autoexection'
- Loading branch information
Showing
9 changed files
with
75 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
To call a function in an expression, rivets includes a special formatter `call`. This formatter will call the function, any formatter parameter will become an argument sent to the function. The following text binding will call the function `event.duration` with the two arguments `event.start` and `event.end`. | ||
|
||
```html | ||
<span rv-text="event.duration | call event.start event.end"></span> | ||
``` | ||
`event.duration` will be called again every time `event.start` and `event.end` change |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
describe("Rivets.formatters", function() { | ||
|
||
describe("call", function() { | ||
var model | ||
|
||
beforeEach(function() { | ||
model = { | ||
fn: function(arg1, arg2) { | ||
return '' + arg1 + arg2; | ||
} | ||
} | ||
}) | ||
|
||
it("calls function with arguments", function() { | ||
rivets.formatters['call'](model.fn, 'foo', 'bar').should.equal('foobar') | ||
}) | ||
|
||
it("calls function with the model as context", function() { | ||
model.obj = { | ||
name: 'foo', | ||
fn: function() { | ||
return this.name; | ||
} | ||
} | ||
var el = document.createElement('div') | ||
el.setAttribute('rv-text', 'obj.fn | call') | ||
rivets.bind(el, model) | ||
el.innerText.should.equal('foo') | ||
}) | ||
}) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Core formatters | ||
|
||
# Calls a function with arguments | ||
Rivets.public.formatters['call'] = (value, args...) -> | ||
value.call @, args... | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters