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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 45cd6f3520b9d10ebd07a57a5e12c64d6937b78e
4
- data.tar.gz: 367c05faac95b64d15b657d1a8bab94f2578856f
3
+ metadata.gz: f140d7e9fc73852eb4540011ac6fd6402c1ac1eb
4
+ data.tar.gz: fee17967d6ed8e26a976e26c96f6d9643e5398d7
5
5
  SHA512:
6
- metadata.gz: e57d2b539882d8f1725c30e4ae00ab294b2a90b204b9f912345f7767e9800881d88052a8665d36dadbef47622eb9da81c2c2676e45d04af3f1ed55cda085016d
7
- data.tar.gz: b81dad2ff9c9086e6830060cdc295c4792f3f966707f2fe95ebf04f0de3673386d83c32a5592e0e44c1c4667955c7b049cd9a89dda48fd18facdb58df27c57ff
6
+ metadata.gz: fb4d0bbc1dfca707cbf1554389acaa5cd19ef403c2573e5de029412221ed6ec7303fe28b2513d7d856c90b9c5b64c7725638069f638efbfc39285d2ac3380390
7
+ data.tar.gz: ce15bf55d94a3b91e31750b301c1579a735a8df4186460c710adc4d1734bc6ae431de2dd0f80c5e7fdaac93a16f2f9d5f49a3083905b46133233e34abc53701a
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- transistor (0.1.4)
4
+ transistor (0.1.5)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -1 +1 @@
1
- if(window.Transistor===undefined){window.Transistor={}}(function(f){var j=(function(){return function(k,l){var m,a,c,i;m=(function(){return{}}());a=new Backbone.Collection();c={add:a.add,remove:a.remove,reset:a.reset,set:a.set};(function(e){var h=true,g=function(d){e[d]=(function(b){return function(){if(h){throw"BackboneCollection is not mutable by user.";}else{return c[b].apply(a,arguments)}}}(d))};c.unfreeze=function(){h=false};c.freeze=function(){h=true};c.unfrozen=function(b){c.unfreeze();b();c.freeze()};g('add');g('remove');g('reset');g('set')}(a));i=f.Binder({set:function(e){c.unfrozen(function(){var d=_.map(e,function(b){return new Backbone.Model(b)});a.reset(d)})},insert:function(b){c.unfrozen(function(){a.add(new Backbone.Model(b))})},update:function(d,e){c.unfrozen(function(){var b=a.get(d);b.clear({silent:true});b.set(e)})},remove:function(d){c.unfrozen(function(){var b=a.get(d);a.remove(b)})}});k.tune(l,i);return a}}());if(f.Backbone===undefined){f.Backbone={}}f.Backbone.Collection=j}(window.Transistor));
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 (radio, channel) {
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 frozen = true,
39
+ var privatized = true,
28
40
  delegate = function (func) {
29
41
  writer[func] = (function (name) {
30
42
  return function () {
31
- if (frozen) {
32
- throw "BackboneCollection is not mutable by user.";
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
- collection_interface.unfreeze();
57
+ privatized = false;
50
58
  unfrozen_context();
51
- collection_interface.freeze();
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 (radio, channel) {
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 frozen = true,
39
+ var privatized = true,
28
40
  delegate = function (func) {
29
41
  writer[func] = (function (name) {
30
42
  return function () {
31
- if (frozen) {
32
- throw "BackboneCollection is not mutable by user.";
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
- collection_interface.unfreeze();
57
+ privatized = false;
50
58
  unfrozen_context();
51
- collection_interface.freeze();
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 (radio, channel) {
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 frozen = true,
39
+ var privatized = true,
28
40
  delegate = function (func) {
29
41
  writer[func] = (function (name) {
30
42
  return function () {
31
- if (frozen) {
32
- throw "BackboneCollection is not mutable by user.";
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
- collection_interface.unfreeze();
57
+ privatized = false;
50
58
  unfrozen_context();
51
- collection_interface.freeze();
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(radio, 'news')
23
- console.log(collection)
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 per default (readonly)", function () {
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
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "transistor"
5
- spec.version = "0.1.4"
5
+ spec.version = "0.1.5"
6
6
 
7
7
  spec.authors = ["Jakob Holderbaum"]
8
8
  spec.email = ["jakob@featurefabrik.de"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: transistor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jakob Holderbaum