-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathbindings.js
More file actions
107 lines (95 loc) · 2.92 KB
/
Copy pathbindings.js
File metadata and controls
107 lines (95 loc) · 2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
require('reactive-ie8-shims');
var domify = require('domify');
var assert = require('assert');
var reactive = require('../');
describe('reactive.bind(name, fn)', function(){
it('should define a new binding', function(done){
var el = domify('<div><h1 data-editable="/item/12">Title</h1></div>');
var react = reactive(el, {}, {
bindings: {
'data-editable': function(el, url){
el.setAttribute('contenteditable', 'true');
assert('/item/12' == url);
}
}
});
assert(el.children[0].getAttribute('contenteditable'));
done();
})
it('should pass bindings onto each', function(done){
var el = domify('<div><h1 each="todos"><span lowercase="title"></span></h1></div>');
var model = {
todos: [ { title: 'test title' } ]
};
var react = reactive(el, model, {
bindings: {
'lowercase': function(el, prop){
var binding = this;
assert(prop === 'title');
var val = binding.value(prop);
assert(val === 'test title');
done();
}
}
});
});
})
describe('reactive.bind(obj)', function(){
it('should define several bindings', function(done){
var el = domify('<div><h1 hello="world">Title</h1></div>');
var react = reactive(el, {}, {
bindings: {
'hello': function(el, val){
assert('world' == val);
done();
}
}
});
})
})
describe('Reactive#bind(name, fn)', function(){
it('should initialize a view-specific binding', function(done){
var el = domify('<ul><li removable></li></ul>');
var view = reactive(el, {}, {
bindings: {
'removable': function(el){
assert('LI' == el.nodeName);
done();
}
}
});
})
it('should support root-level bindings', function(done){
var el = domify('<ul removable><li></li></ul>');
var view = reactive(el, {}, {
bindings: {
'removable': function(el){
assert('UL' == el.nodeName);
done();
}
}
});
})
})
describe('Reactive#bind(name, fn)', function(){
it('should not use setAttribute to update input\'s value', function(){
var el = domify('<input data-value="value" />');
var view = reactive(el, { value: 'old value' });
view.el.value = 'old value';
assert(el.value == 'old value');
view.set('value', 'value');
assert(el.value == 'value');
})
it('should not use setAttribute to update textarea\'s value', function(){
var el = domify('<textarea data-value="value"></textarea>');
var view = reactive(el, { value: 'old value' });
view.set('value', 'value');
assert(el.value == 'value');
})
it('should change value of `.value` to update textarea\'s text content', function(){
var el = domify('<textarea data-text="value"></textarea>');
var view = reactive(el, { value: 'old value' });
view.set('value', 'value');
assert(el.value == 'value');
})
})