transistor 0.1.8 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/build/min/transistor-backbone.js +1 -1
- data/build/src/transistor-backbone.js +12 -1
- data/js/transistor/backbone-collection.js +12 -1
- data/lib/assets/javascripts/transistor-backbone.js +12 -1
- data/spec/javascripts/TransistorBackboneCollectionSpec.js +28 -1
- data/transistor.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6fa2fb97b82ed9da0687e0d99cccc68021cd5fbe
|
4
|
+
data.tar.gz: f1ff0eea8dc9a6bc7c3a6ef41ed47073a0e16a22
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e0e763d07c5715fbb914666b2116b819db5d7400f04f9886e1e26f825a92f0843be859a1629e72072a1549019f513ff92dfd734bfa5344fc234d237e88b1241
|
7
|
+
data.tar.gz: c6d3bcb075ecaad4721090408a9fa5cde9290f8a978c85c1a41713443333f174d40cc422c8ae15173be54ef189f16958c36f0e751b0670b789449604c439e701
|
data/Gemfile.lock
CHANGED
@@ -1 +1 @@
|
|
1
|
-
if(window.Transistor===undefined){window.Transistor={}}(function(i){var p=(function(){return function(j){var k,
|
1
|
+
if(window.Transistor===undefined){window.Transistor={}}(function(i){var p=(function(){return function(j){var k,g,n,e,q,b,f,h,o;k=j.backbone;g=j.channel;n=j.radio;e=j.control;q=(function(){return{}}());b=new k.Collection();b.on('change',function(a){var c=_.clone(a.attributes),d=a.id;if(!e){throw"BackboneCollection is not mutable by user. The model with id "+a.id+" has been changed";}else{delete c.id;e.update(g,d,c)}});f={add:b.add,remove:b.remove,reset:b.reset,set:b.set};h={add:function(a){e.insert(g,a)},remove:function(a){e.remove(g,a.id)},set:function(a){e.set(g,a)}};h.reset=h.set;(function(d){var m=true,l=function(c){d[c]=(function(a){return function(){if(m){if(!e){throw"BackboneCollection is not mutable by user.";}else{h[a].apply(h,arguments)}}else{return f[a].apply(b,arguments)}}}(c))};f.asPublic=function(a){m=false;a();m=true};l('add');l('remove');l('reset');l('set')}(b));o=i.Binder({set:function(d){f.asPublic(function(){var a=[],c;for(c=0;c<d.length;c+=1){a.push(new k.Model(d[c]))}b.set(a)})},insert:function(a){f.asPublic(function(){b.add(new k.Model(a))})},update:function(c,d){f.asPublic(function(){var a=b.get(c);a.clear({silent:true});a.set(d,{silent:true})})},remove:function(c){f.asPublic(function(){var a=b.get(c);b.remove(a)})}});n.tune(g,o);return b}}());if(i.Backbone===undefined){i.Backbone={}}i.Backbone.Collection=p}(window.Transistor));
|
@@ -21,6 +21,17 @@ if (window.Transistor === undefined) {
|
|
21
21
|
}());
|
22
22
|
|
23
23
|
backbone_collection = new Backbone.Collection();
|
24
|
+
backbone_collection.on('change', function (model) {
|
25
|
+
var entry = _.clone(model.attributes),
|
26
|
+
id = model.id;
|
27
|
+
|
28
|
+
if (!control) {
|
29
|
+
throw "BackboneCollection is not mutable by user. The model with id "+model.id+" has been changed";
|
30
|
+
} else {
|
31
|
+
delete entry.id;
|
32
|
+
control.update(channel, id, entry);
|
33
|
+
}
|
34
|
+
});
|
24
35
|
|
25
36
|
collection_interface = {
|
26
37
|
add: backbone_collection.add,
|
@@ -87,7 +98,7 @@ if (window.Transistor === undefined) {
|
|
87
98
|
collection_interface.asPublic(function () {
|
88
99
|
var model = backbone_collection.get(id);
|
89
100
|
model.clear({silent: true});
|
90
|
-
model.set(entry);
|
101
|
+
model.set(entry, {silent: true});
|
91
102
|
});
|
92
103
|
},
|
93
104
|
remove: function (id) {
|
@@ -21,6 +21,17 @@ if (window.Transistor === undefined) {
|
|
21
21
|
}());
|
22
22
|
|
23
23
|
backbone_collection = new Backbone.Collection();
|
24
|
+
backbone_collection.on('change', function (model) {
|
25
|
+
var entry = _.clone(model.attributes),
|
26
|
+
id = model.id;
|
27
|
+
|
28
|
+
if (!control) {
|
29
|
+
throw "BackboneCollection is not mutable by user. The model with id "+model.id+" has been changed";
|
30
|
+
} else {
|
31
|
+
delete entry.id;
|
32
|
+
control.update(channel, id, entry);
|
33
|
+
}
|
34
|
+
});
|
24
35
|
|
25
36
|
collection_interface = {
|
26
37
|
add: backbone_collection.add,
|
@@ -87,7 +98,7 @@ if (window.Transistor === undefined) {
|
|
87
98
|
collection_interface.asPublic(function () {
|
88
99
|
var model = backbone_collection.get(id);
|
89
100
|
model.clear({silent: true});
|
90
|
-
model.set(entry);
|
101
|
+
model.set(entry, {silent: true});
|
91
102
|
});
|
92
103
|
},
|
93
104
|
remove: function (id) {
|
@@ -21,6 +21,17 @@ if (window.Transistor === undefined) {
|
|
21
21
|
}());
|
22
22
|
|
23
23
|
backbone_collection = new Backbone.Collection();
|
24
|
+
backbone_collection.on('change', function (model) {
|
25
|
+
var entry = _.clone(model.attributes),
|
26
|
+
id = model.id;
|
27
|
+
|
28
|
+
if (!control) {
|
29
|
+
throw "BackboneCollection is not mutable by user. The model with id "+model.id+" has been changed";
|
30
|
+
} else {
|
31
|
+
delete entry.id;
|
32
|
+
control.update(channel, id, entry);
|
33
|
+
}
|
34
|
+
});
|
24
35
|
|
25
36
|
collection_interface = {
|
26
37
|
add: backbone_collection.add,
|
@@ -87,7 +98,7 @@ if (window.Transistor === undefined) {
|
|
87
98
|
collection_interface.asPublic(function () {
|
88
99
|
var model = backbone_collection.get(id);
|
89
100
|
model.clear({silent: true});
|
90
|
-
model.set(entry);
|
101
|
+
model.set(entry, {silent: true});
|
91
102
|
});
|
92
103
|
},
|
93
104
|
remove: function (id) {
|
@@ -45,13 +45,28 @@ describe("Transistor.Backbone.Collection", function () {
|
|
45
45
|
}).toThrow(new Error('BackboneCollection is not mutable by user.'));
|
46
46
|
|
47
47
|
});
|
48
|
+
|
49
|
+
it('fails also on a model', function () {
|
50
|
+
radio.trigger('news', 'init', [{id: 100, a:2, b:3}, {id: 101, a:12, b:23}]);
|
51
|
+
|
52
|
+
var model = collection.get(100);
|
53
|
+
|
54
|
+
expect(function () {
|
55
|
+
model.set('a', 0);
|
56
|
+
}).toThrow(new Error('BackboneCollection is not mutable by user. The model with id 100 has been changed'));
|
57
|
+
|
58
|
+
assertEqual(2, collection.get(100)get('a'));
|
59
|
+
});
|
48
60
|
});
|
49
61
|
|
50
62
|
describe('write access via control', function () {
|
51
63
|
beforeEach(function () {
|
52
64
|
control = (function () {
|
53
65
|
var calls = [],
|
54
|
-
record = function (call, args) {
|
66
|
+
record = function (call, args) {
|
67
|
+
console.log('call', call, args)
|
68
|
+
calls.push([call, args])
|
69
|
+
};
|
55
70
|
return {
|
56
71
|
set: function () { record("set", arguments); },
|
57
72
|
insert: function () { record("insert", arguments); },
|
@@ -104,6 +119,18 @@ describe("Transistor.Backbone.Collection", function () {
|
|
104
119
|
['set', ['news', [{a: 12}, {b: 13}]]]
|
105
120
|
]);
|
106
121
|
});
|
122
|
+
|
123
|
+
it('delegates model change events to update', function () {
|
124
|
+
radio.trigger('news', 'init', [{id: 100, a:2, b:3}, {id: 101, a:12, b:23}]);
|
125
|
+
|
126
|
+
var model = collection.get(101);
|
127
|
+
|
128
|
+
model.set('a', 24);
|
129
|
+
|
130
|
+
assertEqual(control.calls, [
|
131
|
+
['update', ['news', 101, {a: 24, b:23}]]
|
132
|
+
]);
|
133
|
+
})
|
107
134
|
});
|
108
135
|
|
109
136
|
describe("init event", function () {
|
data/transistor.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: transistor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jakob Holderbaum
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-06-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|