Open
Description
Reactive should be able interpolate functions.
The above suite tests <div>{ ret("foo") }</div>
when ret
is defined in the model or the view.
Only this.ret
seems to work.
Here I'm testing ways to declare the function:
fn: String -> String
fn: -> (String -> String)
(see lib/index.js#L140, lib/adapter.js#L81)
Tests
var assert = require('assert');
var domify = require('domify');
var reactive = require('reactive');
describe('Model function', function() {
it('this.fn()', function() {
var el = domify('<div>{ this.ret("foo") }</div>');
var view = reactive(el, {ret: String});
assert('foo' == el.textContent);
});
it('fn() with fn: String -> String', function() {
var el = domify('<div>{ ret("foo") }</div>');
var view = reactive(el, {ret: String});
assert('foo' == el.textContent);
});
it('fn() with fn: -> (String -> String)', function() {
var el = domify('<div>{ ret("foo") }</div>');
var view = reactive(el, {ret: function() { return String }});
assert('foo' == el.textContent);
});
});
describe('View function', function() {
it('fn() with fn: String -> String', function() {
var el = domify('<div>{ ret("foo") }</div>');
var view = reactive(el, {}, {delegate: {ret: String}});
assert('foo' == el.textContent);
});
it('fn() with fn: -> (String -> String)', function() {
var el = domify('<div>{ ret("foo") }</div>');
var view = reactive(el, {}, {delegate: {ret: function() { return String }}});
assert('foo' == el.textContent);
});
});
Result
Model function
✓ this.fn()
2) fn() with fn: String -> String
3) fn() with fn: -> (String -> String)
View function
4) fn() with fn: String -> String
5) fn() with fn: -> (String -> String)
The last 4 tests raise an error:
// Uncaught TypeError: object is not a function VM2169:3
(function(reactive
/**/) {
return ['ret']('foo')
})
Metadata
Metadata
Assignees
Labels
No labels