transistor 0.1.8 → 0.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5242812c3750c6ee59145051f4c6d2d59acd23fa
4
- data.tar.gz: 846c98563b15147ca787ae4e404cbaddb48f31ff
3
+ metadata.gz: 6fa2fb97b82ed9da0687e0d99cccc68021cd5fbe
4
+ data.tar.gz: f1ff0eea8dc9a6bc7c3a6ef41ed47073a0e16a22
5
5
  SHA512:
6
- metadata.gz: 81d53501ae3943a0a11d1e6f17b19df1987488a971d7a94fea45aa5b36275c3b1a4a07c717108ecb6b2ec617b483af284c9b11486228ed0b9d86ef39216882fe
7
- data.tar.gz: 599a2d62bdf1b622b5016deed58c637dc0c5a9929221d8905f0eac4b27cb47b678c230e6d0204422a251b0bc8db8f2af80ad9fcc5484b18d7401a28ce7d9e1c0
6
+ metadata.gz: 7e0e763d07c5715fbb914666b2116b819db5d7400f04f9886e1e26f825a92f0843be859a1629e72072a1549019f513ff92dfd734bfa5344fc234d237e88b1241
7
+ data.tar.gz: c6d3bcb075ecaad4721090408a9fa5cde9290f8a978c85c1a41713443333f174d40cc422c8ae15173be54ef189f16958c36f0e751b0670b789449604c439e701
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- transistor (0.1.8)
4
+ transistor (0.1.9)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -1 +1 @@
1
- if(window.Transistor===undefined){window.Transistor={}}(function(i){var p=(function(){return function(j){var k,f,n,g,q,b,d,h,o;k=j.backbone;f=j.channel;n=j.radio;g=j.control;q=(function(){return{}}());b=new k.Collection();d={add:b.add,remove:b.remove,reset:b.reset,set:b.set};h={add:function(a){g.insert(f,a)},remove:function(a){g.remove(f,a.id)},set:function(a){g.set(f,a)}};h.reset=h.set;(function(e){var m=true,l=function(c){e[c]=(function(a){return function(){if(m){if(!g){throw"BackboneCollection is not mutable by user.";}else{h[a].apply(h,arguments)}}else{return d[a].apply(b,arguments)}}}(c))};d.asPublic=function(a){m=false;a();m=true};l('add');l('remove');l('reset');l('set')}(b));o=i.Binder({set:function(e){d.asPublic(function(){var a=[],c;for(c=0;c<e.length;c+=1){a.push(new k.Model(e[c]))}b.set(a)})},insert:function(a){d.asPublic(function(){b.add(new k.Model(a))})},update:function(c,e){d.asPublic(function(){var a=b.get(c);a.clear({silent:true});a.set(e)})},remove:function(c){d.asPublic(function(){var a=b.get(c);b.remove(a)})}});n.tune(f,o);return b}}());if(i.Backbone===undefined){i.Backbone={}}i.Backbone.Collection=p}(window.Transistor));
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) { calls.push([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
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "transistor"
5
- spec.version = "0.1.8"
5
+ spec.version = "0.1.9"
6
6
 
7
7
  spec.authors = ["Jakob Holderbaum"]
8
8
  spec.email = ["jakob@featurefabrik.de"]
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.8
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-05-21 00:00:00.000000000 Z
11
+ date: 2013-06-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler