Skip to content

Reactive should interpolate functions #154

@ooflorent

Description

@ooflorent

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:

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions