transistor 0.1.4 → 0.1.5
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 +23 -15
- data/js/transistor/backbone-collection.js +23 -15
- data/lib/assets/javascripts/transistor-backbone.js +23 -15
- data/spec/javascripts/TransistorBackboneCollectionSpec.js +65 -5
- data/transistor.gemspec +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f140d7e9fc73852eb4540011ac6fd6402c1ac1eb
|
4
|
+
data.tar.gz: fee17967d6ed8e26a976e26c96f6d9643e5398d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb4d0bbc1dfca707cbf1554389acaa5cd19ef403c2573e5de029412221ed6ec7303fe28b2513d7d856c90b9c5b64c7725638069f638efbfc39285d2ac3380390
|
7
|
+
data.tar.gz: ce15bf55d94a3b91e31750b301c1579a735a8df4186460c710adc4d1734bc6ae431de2dd0f80c5e7fdaac93a16f2f9d5f49a3083905b46133233e34abc53701a
|
data/Gemfile.lock
CHANGED
@@ -1 +1 @@
|
|
1
|
-
if(window.Transistor===undefined){window.Transistor={}}(function(
|
1
|
+
if(window.Transistor===undefined){window.Transistor={}}(function(i){var o=(function(){return function(k){var e,m,f,p,b,d,g,n;e=k.channel;m=k.radio;f=k.control;p=(function(){return{}}());b=new Backbone.Collection();d={add:b.add,remove:b.remove,reset:b.reset,set:b.set};g={add:function(a){f.insert(e,a)},remove:function(a){f.remove(e,a.id)},set:function(a){f.set(e,a)}};g.reset=g.set;(function(h){var l=true,j=function(c){h[c]=(function(a){return function(){if(l){if(!f){throw"BackboneCollection is not mutable by user.";}else{g[a].apply(g,arguments)}}else{return d[a].apply(b,arguments)}}}(c))};d.unfrozen=function(a){l=false;a();l=true};j('add');j('remove');j('reset');j('set')}(b));n=i.Binder({set:function(h){d.unfrozen(function(){var c=_.map(h,function(a){return new Backbone.Model(a)});b.reset(c)})},insert:function(a){d.unfrozen(function(){b.add(new Backbone.Model(a))})},update:function(c,h){d.unfrozen(function(){var a=b.get(c);a.clear({silent:true});a.set(h)})},remove:function(c){d.unfrozen(function(){var a=b.get(c);b.remove(a)})}});m.tune(e,n);return b}}());if(i.Backbone===undefined){i.Backbone={}}i.Backbone.Collection=o}(window.Transistor));
|
@@ -6,8 +6,13 @@ if (window.Transistor === undefined) {
|
|
6
6
|
|
7
7
|
(function (transistor) {
|
8
8
|
var BackboneCollection = (function () {
|
9
|
-
return function (
|
10
|
-
var H, backbone_collection, collection_interface, binder;
|
9
|
+
return function (options) {
|
10
|
+
var channel, radio, control, H, backbone_collection, collection_interface, control_interface, binder;
|
11
|
+
|
12
|
+
channel = options.channel;
|
13
|
+
radio = options.radio;
|
14
|
+
control = options.control;
|
15
|
+
|
11
16
|
|
12
17
|
H = (function () {
|
13
18
|
return {
|
@@ -23,13 +28,24 @@ if (window.Transistor === undefined) {
|
|
23
28
|
set: backbone_collection.set
|
24
29
|
};
|
25
30
|
|
31
|
+
control_interface = {
|
32
|
+
add: function (entry) { control.insert(channel, entry); },
|
33
|
+
remove: function (model) { control.remove(channel, model.id); },
|
34
|
+
set: function (collection) { control.set(channel, collection); }
|
35
|
+
};
|
36
|
+
control_interface.reset = control_interface.set;
|
37
|
+
|
26
38
|
(function (writer) {
|
27
|
-
var
|
39
|
+
var privatized = true,
|
28
40
|
delegate = function (func) {
|
29
41
|
writer[func] = (function (name) {
|
30
42
|
return function () {
|
31
|
-
if (
|
32
|
-
|
43
|
+
if (privatized) {
|
44
|
+
if (!control) {
|
45
|
+
throw "BackboneCollection is not mutable by user.";
|
46
|
+
} else {
|
47
|
+
control_interface[name].apply(control_interface, arguments);
|
48
|
+
}
|
33
49
|
} else {
|
34
50
|
return collection_interface[name].apply(backbone_collection, arguments);
|
35
51
|
}
|
@@ -37,18 +53,10 @@ if (window.Transistor === undefined) {
|
|
37
53
|
}(func));
|
38
54
|
};
|
39
55
|
|
40
|
-
collection_interface.unfreeze = function () {
|
41
|
-
frozen = false;
|
42
|
-
};
|
43
|
-
|
44
|
-
collection_interface.freeze = function () {
|
45
|
-
frozen = true;
|
46
|
-
};
|
47
|
-
|
48
56
|
collection_interface.unfrozen = function (unfrozen_context) {
|
49
|
-
|
57
|
+
privatized = false;
|
50
58
|
unfrozen_context();
|
51
|
-
|
59
|
+
privatized = true;
|
52
60
|
};
|
53
61
|
|
54
62
|
delegate('add');
|
@@ -6,8 +6,13 @@ if (window.Transistor === undefined) {
|
|
6
6
|
|
7
7
|
(function (transistor) {
|
8
8
|
var BackboneCollection = (function () {
|
9
|
-
return function (
|
10
|
-
var H, backbone_collection, collection_interface, binder;
|
9
|
+
return function (options) {
|
10
|
+
var channel, radio, control, H, backbone_collection, collection_interface, control_interface, binder;
|
11
|
+
|
12
|
+
channel = options.channel;
|
13
|
+
radio = options.radio;
|
14
|
+
control = options.control;
|
15
|
+
|
11
16
|
|
12
17
|
H = (function () {
|
13
18
|
return {
|
@@ -23,13 +28,24 @@ if (window.Transistor === undefined) {
|
|
23
28
|
set: backbone_collection.set
|
24
29
|
};
|
25
30
|
|
31
|
+
control_interface = {
|
32
|
+
add: function (entry) { control.insert(channel, entry); },
|
33
|
+
remove: function (model) { control.remove(channel, model.id); },
|
34
|
+
set: function (collection) { control.set(channel, collection); }
|
35
|
+
};
|
36
|
+
control_interface.reset = control_interface.set;
|
37
|
+
|
26
38
|
(function (writer) {
|
27
|
-
var
|
39
|
+
var privatized = true,
|
28
40
|
delegate = function (func) {
|
29
41
|
writer[func] = (function (name) {
|
30
42
|
return function () {
|
31
|
-
if (
|
32
|
-
|
43
|
+
if (privatized) {
|
44
|
+
if (!control) {
|
45
|
+
throw "BackboneCollection is not mutable by user.";
|
46
|
+
} else {
|
47
|
+
control_interface[name].apply(control_interface, arguments);
|
48
|
+
}
|
33
49
|
} else {
|
34
50
|
return collection_interface[name].apply(backbone_collection, arguments);
|
35
51
|
}
|
@@ -37,18 +53,10 @@ if (window.Transistor === undefined) {
|
|
37
53
|
}(func));
|
38
54
|
};
|
39
55
|
|
40
|
-
collection_interface.unfreeze = function () {
|
41
|
-
frozen = false;
|
42
|
-
};
|
43
|
-
|
44
|
-
collection_interface.freeze = function () {
|
45
|
-
frozen = true;
|
46
|
-
};
|
47
|
-
|
48
56
|
collection_interface.unfrozen = function (unfrozen_context) {
|
49
|
-
|
57
|
+
privatized = false;
|
50
58
|
unfrozen_context();
|
51
|
-
|
59
|
+
privatized = true;
|
52
60
|
};
|
53
61
|
|
54
62
|
delegate('add');
|
@@ -6,8 +6,13 @@ if (window.Transistor === undefined) {
|
|
6
6
|
|
7
7
|
(function (transistor) {
|
8
8
|
var BackboneCollection = (function () {
|
9
|
-
return function (
|
10
|
-
var H, backbone_collection, collection_interface, binder;
|
9
|
+
return function (options) {
|
10
|
+
var channel, radio, control, H, backbone_collection, collection_interface, control_interface, binder;
|
11
|
+
|
12
|
+
channel = options.channel;
|
13
|
+
radio = options.radio;
|
14
|
+
control = options.control;
|
15
|
+
|
11
16
|
|
12
17
|
H = (function () {
|
13
18
|
return {
|
@@ -23,13 +28,24 @@ if (window.Transistor === undefined) {
|
|
23
28
|
set: backbone_collection.set
|
24
29
|
};
|
25
30
|
|
31
|
+
control_interface = {
|
32
|
+
add: function (entry) { control.insert(channel, entry); },
|
33
|
+
remove: function (model) { control.remove(channel, model.id); },
|
34
|
+
set: function (collection) { control.set(channel, collection); }
|
35
|
+
};
|
36
|
+
control_interface.reset = control_interface.set;
|
37
|
+
|
26
38
|
(function (writer) {
|
27
|
-
var
|
39
|
+
var privatized = true,
|
28
40
|
delegate = function (func) {
|
29
41
|
writer[func] = (function (name) {
|
30
42
|
return function () {
|
31
|
-
if (
|
32
|
-
|
43
|
+
if (privatized) {
|
44
|
+
if (!control) {
|
45
|
+
throw "BackboneCollection is not mutable by user.";
|
46
|
+
} else {
|
47
|
+
control_interface[name].apply(control_interface, arguments);
|
48
|
+
}
|
33
49
|
} else {
|
34
50
|
return collection_interface[name].apply(backbone_collection, arguments);
|
35
51
|
}
|
@@ -37,18 +53,10 @@ if (window.Transistor === undefined) {
|
|
37
53
|
}(func));
|
38
54
|
};
|
39
55
|
|
40
|
-
collection_interface.unfreeze = function () {
|
41
|
-
frozen = false;
|
42
|
-
};
|
43
|
-
|
44
|
-
collection_interface.freeze = function () {
|
45
|
-
frozen = true;
|
46
|
-
};
|
47
|
-
|
48
56
|
collection_interface.unfrozen = function (unfrozen_context) {
|
49
|
-
|
57
|
+
privatized = false;
|
50
58
|
unfrozen_context();
|
51
|
-
|
59
|
+
privatized = true;
|
52
60
|
};
|
53
61
|
|
54
62
|
delegate('add');
|
@@ -1,5 +1,5 @@
|
|
1
1
|
describe("Transistor.Backbone.Collection", function () {
|
2
|
-
var radio, collection;
|
2
|
+
var radio, control, collection;
|
3
3
|
|
4
4
|
beforeEach(function () {
|
5
5
|
radio = (function () {
|
@@ -19,12 +19,14 @@ describe("Transistor.Backbone.Collection", function () {
|
|
19
19
|
return stub;
|
20
20
|
}());
|
21
21
|
|
22
|
-
collection = Transistor.Backbone.Collection(
|
23
|
-
|
22
|
+
collection = Transistor.Backbone.Collection({
|
23
|
+
channel: 'news',
|
24
|
+
radio: radio
|
25
|
+
})
|
24
26
|
});
|
25
27
|
|
26
|
-
describe("write access", function () {
|
27
|
-
it("is not granted
|
28
|
+
describe("default write access", function () {
|
29
|
+
it("is not granted", function () {
|
28
30
|
expect(function () {
|
29
31
|
collection.add({})
|
30
32
|
}).toThrow(new Error('BackboneCollection is not mutable by user.'));
|
@@ -44,6 +46,64 @@ describe("Transistor.Backbone.Collection", function () {
|
|
44
46
|
});
|
45
47
|
});
|
46
48
|
|
49
|
+
describe('write access via control', function () {
|
50
|
+
beforeEach(function () {
|
51
|
+
control = (function () {
|
52
|
+
var calls = [],
|
53
|
+
record = function (call, args) { calls.push([call, args]) };
|
54
|
+
return {
|
55
|
+
set: function () { record("set", arguments); },
|
56
|
+
insert: function () { record("insert", arguments); },
|
57
|
+
update: function () { record("update", arguments); },
|
58
|
+
remove: function () { record("remove", arguments); },
|
59
|
+
calls: calls
|
60
|
+
};
|
61
|
+
}());
|
62
|
+
|
63
|
+
collection = Transistor.Backbone.Collection({
|
64
|
+
channel: 'news',
|
65
|
+
radio: radio,
|
66
|
+
control: control
|
67
|
+
});
|
68
|
+
});
|
69
|
+
|
70
|
+
it('delegates add to insert', function () {
|
71
|
+
collection.add({a: 12, b: 13});
|
72
|
+
|
73
|
+
assertEqual(control.calls, [
|
74
|
+
['insert', ['news', {a: 12, b: 13}]]
|
75
|
+
]);
|
76
|
+
});
|
77
|
+
|
78
|
+
it('delegates remove to remove', function () {
|
79
|
+
radio.trigger('news', 'init', [{id: 100, a:2, b:3}, {id: 101, a:12, b:23}]);
|
80
|
+
|
81
|
+
var model = collection.get(101);
|
82
|
+
|
83
|
+
collection.remove(model)
|
84
|
+
|
85
|
+
assertEqual(control.calls, [
|
86
|
+
['remove', ['news', 101]]
|
87
|
+
]);
|
88
|
+
});
|
89
|
+
|
90
|
+
it('delegates reset to set', function () {
|
91
|
+
collection.reset([{a: 12}, {b: 13}])
|
92
|
+
|
93
|
+
assertEqual(control.calls, [
|
94
|
+
['set', ['news', [{a: 12}, {b: 13}]]]
|
95
|
+
]);
|
96
|
+
});
|
97
|
+
|
98
|
+
it('delegates set to set', function () {
|
99
|
+
collection.set([{a: 12}, {b: 13}])
|
100
|
+
|
101
|
+
assertEqual(control.calls, [
|
102
|
+
['set', ['news', [{a: 12}, {b: 13}]]]
|
103
|
+
]);
|
104
|
+
});
|
105
|
+
});
|
106
|
+
|
47
107
|
describe("init event", function () {
|
48
108
|
it("maps arg 'array' to a clear and set", function () {
|
49
109
|
radio.trigger('news', 'init', [{a:2, b:3}, {a:12, b:23}]);
|
data/transistor.gemspec
CHANGED