joosy 1.2.0.alpha.70 → 1.2.0.alpha.71

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: 0c0650d2b49ebccea7dfe767a26b0dc38db9871d
4
- data.tar.gz: 936ce56008fbf989e1283776d5755af3a9aae82e
3
+ metadata.gz: 0dee5804bf618851443ae7da79979ae1ba847e23
4
+ data.tar.gz: 733416f347d8bc7ea08f1a84418b89d633f9fe9e
5
5
  SHA512:
6
- metadata.gz: 0a3a635da761bc635707176b166d5d8418b211efaff7f0985386a75370128c94c2faf5fc66f6792ed0f2a3b4a7899600fc1acb456bfd05971152e4ce83c80128
7
- data.tar.gz: ba2f0bcb06ca85faa460ab4f428cbd847d907e989199dcd73f285693925ff3232b3b06ade4b2bfee2b6db522377fde198344279c8aae09f2d054c5763f22afea
6
+ metadata.gz: 8a80dd2a1acfcec49e9857758ef5993bb52aa2b6110270d66ae2048eb5f8ee0ea8ff2357686664855425ef1667631f3db6f63f83e054ac481b774baf946e9a74
7
+ data.tar.gz: a93ebfa487fc46b8cd8fbd63d6b43eed9e3f9aecace0fd7c3734f8384afb6017258d8126b89a98dd338d33ccaaf85077394afe1868b64d623ea6138b401967b0
data/bower.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "joosy",
3
- "version": "1.2.0-alpha.70",
3
+ "version": "1.2.0-alpha.71",
4
4
  "main": "build/joosy.js",
5
5
  "ignore": [
6
6
  "lib",
data/build/joosy.js CHANGED
@@ -245,9 +245,27 @@
245
245
 
246
246
  }).call(this);
247
247
  (function() {
248
- var __slice = [].slice;
248
+ var Namespace, SynchronizationContext,
249
+ __slice = [].slice;
250
+
251
+ SynchronizationContext = (function() {
252
+ function SynchronizationContext() {
253
+ this.actions = [];
254
+ }
255
+
256
+ SynchronizationContext.prototype["do"] = function(action) {
257
+ return this.actions.push(action);
258
+ };
259
+
260
+ SynchronizationContext.prototype.after = function(after) {
261
+ this.after = after;
262
+ };
263
+
264
+ return SynchronizationContext;
249
265
 
250
- Joosy.Events.Namespace = (function() {
266
+ })();
267
+
268
+ Namespace = (function() {
251
269
  function Namespace(parent) {
252
270
  this.parent = parent;
253
271
  this.bindings = [];
@@ -273,29 +291,17 @@
273
291
 
274
292
  })();
275
293
 
276
- }).call(this);
277
- (function() {
278
- var SynchronizationContext,
279
- __slice = [].slice;
280
-
281
- SynchronizationContext = (function() {
282
- function SynchronizationContext() {
283
- this.actions = [];
284
- }
285
-
286
- SynchronizationContext.prototype["do"] = function(action) {
287
- return this.actions.push(action);
288
- };
289
-
290
- SynchronizationContext.prototype.after = function(after) {
291
- this.after = after;
292
- };
293
-
294
- return SynchronizationContext;
295
-
296
- })();
297
-
298
294
  Joosy.Modules.Events = {
295
+ eventsNamespace: function(actions) {
296
+ var namespace;
297
+ namespace = new Namespace(this);
298
+ if (actions != null) {
299
+ if (typeof actions.call === "function") {
300
+ actions.call(namespace);
301
+ }
302
+ }
303
+ return namespace;
304
+ },
299
305
  wait: function(name, events, callback) {
300
306
  if (!this.hasOwnProperty('__oneShotEvents')) {
301
307
  this.__oneShotEvents = {};
@@ -1760,7 +1766,11 @@
1760
1766
 
1761
1767
  }).call(this);
1762
1768
  (function() {
1763
- Joosy.Modules.Page_Scrolling = {
1769
+ Joosy.Modules.Page = {};
1770
+
1771
+ }).call(this);
1772
+ (function() {
1773
+ Joosy.Modules.Page.Scrolling = {
1764
1774
  included: function() {
1765
1775
  this.scroll = function(element, options) {
1766
1776
  if (options == null) {
@@ -1805,7 +1815,7 @@
1805
1815
 
1806
1816
  }).call(this);
1807
1817
  (function() {
1808
- Joosy.Modules.Page_Title = {
1818
+ Joosy.Modules.Page.Title = {
1809
1819
  title: function(title, separator) {
1810
1820
  if (separator == null) {
1811
1821
  separator = ' / ';
@@ -1837,9 +1847,9 @@
1837
1847
  return this.prototype.__layoutClass = layoutClass;
1838
1848
  };
1839
1849
 
1840
- Page.include(Joosy.Modules.Page_Scrolling);
1850
+ Page.include(Joosy.Modules.Page.Scrolling);
1841
1851
 
1842
- Page.extend(Joosy.Modules.Page_Title);
1852
+ Page.extend(Joosy.Modules.Page.Title);
1843
1853
 
1844
1854
  function Page(params, previous) {
1845
1855
  var _ref;
@@ -2276,13 +2286,12 @@
2276
2286
 
2277
2287
  Joosy.Module.include.call(Array, Joosy.Modules.Events);
2278
2288
 
2289
+ Joosy.Module.include.call(Array, Joosy.Modules.Filters);
2290
+
2291
+ Array.registerPlainFilters('beforeLoad');
2292
+
2279
2293
  function Array() {
2280
- var entry, _i, _len, _ref;
2281
- _ref = this.slice.call(arguments, 0);
2282
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
2283
- entry = _ref[_i];
2284
- this.push(entry);
2285
- }
2294
+ this.__fillData(arguments, false);
2286
2295
  }
2287
2296
 
2288
2297
  Array.prototype.get = function(index) {
@@ -2292,7 +2301,11 @@
2292
2301
  Array.prototype.set = function(index, value) {
2293
2302
  this[index] = value;
2294
2303
  this.trigger('changed');
2295
- return this.length;
2304
+ return value;
2305
+ };
2306
+
2307
+ Array.prototype.load = function() {
2308
+ return this.__fillData(arguments);
2296
2309
  };
2297
2310
 
2298
2311
  Array.prototype.push = function() {
@@ -2330,6 +2343,26 @@
2330
2343
  return result;
2331
2344
  };
2332
2345
 
2346
+ Array.prototype.__fillData = function(data, notify) {
2347
+ var entry, _i, _len, _ref;
2348
+ if (notify == null) {
2349
+ notify = true;
2350
+ }
2351
+ data = data[0] instanceof Array ? data[0] : this.slice.call(data, 0);
2352
+ if (this.length > 0) {
2353
+ this.splice(0, this.length);
2354
+ }
2355
+ _ref = this.__applyBeforeLoads(data);
2356
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
2357
+ entry = _ref[_i];
2358
+ this.push(entry);
2359
+ }
2360
+ if (notify) {
2361
+ this.trigger('changed');
2362
+ }
2363
+ return null;
2364
+ };
2365
+
2333
2366
  return Array;
2334
2367
 
2335
2368
  })(Array);
@@ -2345,75 +2378,24 @@
2345
2378
  var __hasProp = {}.hasOwnProperty,
2346
2379
  __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
2347
2380
 
2348
- Joosy.Resources.Scalar = (function(_super) {
2349
- __extends(Scalar, _super);
2350
-
2351
- Scalar.include(Joosy.Modules.Events);
2352
-
2353
- function Scalar(value) {
2354
- return Scalar.__super__.constructor.call(this, function() {
2355
- return this.value = value;
2356
- });
2357
- }
2358
-
2359
- Scalar.prototype.__call = function() {
2360
- if (arguments.length > 0) {
2361
- return this.set(arguments[0]);
2362
- } else {
2363
- return this.get();
2364
- }
2365
- };
2366
-
2367
- Scalar.prototype.get = function() {
2368
- return this.value;
2369
- };
2370
-
2371
- Scalar.prototype.set = function(value) {
2372
- this.value = value;
2373
- return this.trigger('changed');
2374
- };
2375
-
2376
- Scalar.prototype.valueOf = function() {
2377
- return this.value.valueOf();
2378
- };
2379
-
2380
- Scalar.prototype.toString = function() {
2381
- return this.value.toString();
2382
- };
2383
-
2384
- return Scalar;
2385
-
2386
- })(Joosy.Function);
2387
-
2388
- if ((typeof define !== "undefined" && define !== null ? define.amd : void 0) != null) {
2389
- define('joosy/resources/scalar', function() {
2390
- return Joosy.Resources.Scalar;
2391
- });
2392
- }
2393
-
2394
- }).call(this);
2395
- (function() {
2396
- var __hasProp = {}.hasOwnProperty,
2397
- __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
2398
-
2399
- Joosy.Resources.Watcher = (function(_super) {
2400
- __extends(Watcher, _super);
2381
+ Joosy.Resources.Cacher = (function(_super) {
2382
+ __extends(Cacher, _super);
2401
2383
 
2402
- Watcher.include(Joosy.Modules.Events);
2384
+ Cacher.include(Joosy.Modules.Events);
2403
2385
 
2404
- Watcher.include(Joosy.Modules.Filters);
2386
+ Cacher.include(Joosy.Modules.Filters);
2405
2387
 
2406
- Watcher.registerPlainFilters('beforeLoad');
2388
+ Cacher.registerPlainFilters('beforeLoad');
2407
2389
 
2408
- Watcher.cache = function(cacheKey) {
2390
+ Cacher.cache = function(cacheKey) {
2409
2391
  return this.prototype.__cacheKey = cacheKey;
2410
2392
  };
2411
2393
 
2412
- Watcher.fetcher = function(fetcher) {
2394
+ Cacher.fetcher = function(fetcher) {
2413
2395
  return this.prototype.__fetcher = fetcher;
2414
2396
  };
2415
2397
 
2416
- function Watcher(callback, cacheKey, fetcher) {
2398
+ function Cacher(callback, cacheKey, fetcher) {
2417
2399
  if (cacheKey == null) {
2418
2400
  cacheKey = false;
2419
2401
  }
@@ -2441,7 +2423,7 @@
2441
2423
  }
2442
2424
  }
2443
2425
 
2444
- Watcher.prototype.clone = function(callback) {
2426
+ Cacher.prototype.clone = function(callback) {
2445
2427
  var copy;
2446
2428
  copy = new this.constructor(callback, this.__cacheKey, this.__fetcher);
2447
2429
  copy.data = Object.clone(this.data, true);
@@ -2449,7 +2431,7 @@
2449
2431
  return copy;
2450
2432
  };
2451
2433
 
2452
- Watcher.prototype.refresh = function(callback) {
2434
+ Cacher.prototype.refresh = function(callback) {
2453
2435
  var _this = this;
2454
2436
  return this.__fetcher(function(result) {
2455
2437
  if (_this.__cacheKey && localStorage) {
@@ -2463,13 +2445,180 @@
2463
2445
  });
2464
2446
  };
2465
2447
 
2466
- return Watcher;
2448
+ return Cacher;
2467
2449
 
2468
2450
  })(Joosy.Module);
2469
2451
 
2470
2452
  if ((typeof define !== "undefined" && define !== null ? define.amd : void 0) != null) {
2471
- define('joosy/resources/watcher', function() {
2472
- return Joosy.Resources.Watcher;
2453
+ define('joosy/resources/cacher', function() {
2454
+ return Joosy.Resources.Cacher;
2455
+ });
2456
+ }
2457
+
2458
+ }).call(this);
2459
+ (function() {
2460
+ var __hasProp = {}.hasOwnProperty,
2461
+ __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
2462
+
2463
+ Joosy.Resources.Hash = (function(_super) {
2464
+ __extends(Hash, _super);
2465
+
2466
+ Hash.include(Joosy.Modules.Events);
2467
+
2468
+ Hash.include(Joosy.Modules.Filters);
2469
+
2470
+ function Hash(data) {
2471
+ if (data == null) {
2472
+ data = {};
2473
+ }
2474
+ return Hash.__super__.constructor.call(this, function() {
2475
+ return this.__fillData(data, false);
2476
+ });
2477
+ }
2478
+
2479
+ Hash.prototype.get = function(path) {
2480
+ var instance, property, _ref;
2481
+ _ref = this.__callTarget(path, true), instance = _ref[0], property = _ref[1];
2482
+ if (!instance) {
2483
+ return void 0;
2484
+ }
2485
+ if (instance instanceof Joosy.Resources.Hash) {
2486
+ return instance(property);
2487
+ } else {
2488
+ return instance[property];
2489
+ }
2490
+ };
2491
+
2492
+ Hash.prototype.set = function(path, value) {
2493
+ var instance, property, _ref;
2494
+ _ref = this.__callTarget(path), instance = _ref[0], property = _ref[1];
2495
+ if (instance instanceof Joosy.Resources.Hash) {
2496
+ instance(property, value);
2497
+ } else {
2498
+ instance[property] = value;
2499
+ }
2500
+ this.trigger('changed');
2501
+ return value;
2502
+ };
2503
+
2504
+ Hash.prototype.load = function(data) {
2505
+ this.__fillData(data);
2506
+ return this;
2507
+ };
2508
+
2509
+ Hash.prototype.__call = function(path, value) {
2510
+ if (arguments.length > 1) {
2511
+ return this.__set(path, value);
2512
+ } else {
2513
+ return this.__get(path);
2514
+ }
2515
+ };
2516
+
2517
+ Hash.prototype.__callTarget = function(path, safe) {
2518
+ var keyword, part, target, _i, _len;
2519
+ if (safe == null) {
2520
+ safe = false;
2521
+ }
2522
+ if (path.indexOf('.') !== -1 && (this.data[path] == null)) {
2523
+ path = path.split('.');
2524
+ keyword = path.pop();
2525
+ target = this.data;
2526
+ for (_i = 0, _len = path.length; _i < _len; _i++) {
2527
+ part = path[_i];
2528
+ if (safe && (target[part] == null)) {
2529
+ return false;
2530
+ }
2531
+ if (target[part] == null) {
2532
+ target[part] = {};
2533
+ }
2534
+ target = target instanceof Joosy.Resources.Hash ? target(part) : target[part];
2535
+ }
2536
+ return [target, keyword];
2537
+ } else {
2538
+ return [this.data, path];
2539
+ }
2540
+ };
2541
+
2542
+ Hash.prototype.__fillData = function(data, notify) {
2543
+ if (notify == null) {
2544
+ notify = true;
2545
+ }
2546
+ this.data = this.__applyBeforeLoads(data);
2547
+ if (notify) {
2548
+ this.trigger('changed');
2549
+ }
2550
+ return null;
2551
+ };
2552
+
2553
+ Hash.prototype.toString = function() {
2554
+ return JSON.stringify(this.data);
2555
+ };
2556
+
2557
+ return Hash;
2558
+
2559
+ })(Joosy.Function);
2560
+
2561
+ if ((typeof define !== "undefined" && define !== null ? define.amd : void 0) != null) {
2562
+ define('joosy/resources/hash', function() {
2563
+ return Joosy.Resources.Hash;
2564
+ });
2565
+ }
2566
+
2567
+ }).call(this);
2568
+ (function() {
2569
+ var __hasProp = {}.hasOwnProperty,
2570
+ __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
2571
+
2572
+ Joosy.Resources.Scalar = (function(_super) {
2573
+ __extends(Scalar, _super);
2574
+
2575
+ Scalar.include(Joosy.Modules.Events);
2576
+
2577
+ Scalar.include(Joosy.Modules.Filters);
2578
+
2579
+ function Scalar(value) {
2580
+ return Scalar.__super__.constructor.call(this, function() {
2581
+ return this.value = value;
2582
+ });
2583
+ }
2584
+
2585
+ Scalar.prototype.get = function() {
2586
+ return this.value;
2587
+ };
2588
+
2589
+ Scalar.prototype.set = function() {
2590
+ return this.load.apply(this, arguments);
2591
+ };
2592
+
2593
+ Scalar.prototype.load = function(value) {
2594
+ this.value = this.__applyBeforeLoads(value);
2595
+ this.trigger('changed');
2596
+ return this.value;
2597
+ };
2598
+
2599
+ Scalar.prototype.__call = function() {
2600
+ if (arguments.length > 0) {
2601
+ return this.set(arguments[0]);
2602
+ } else {
2603
+ return this.get();
2604
+ }
2605
+ };
2606
+
2607
+ Scalar.prototype.valueOf = function() {
2608
+ return this.value.valueOf();
2609
+ };
2610
+
2611
+ Scalar.prototype.toString = function() {
2612
+ return this.value.toString();
2613
+ };
2614
+
2615
+ return Scalar;
2616
+
2617
+ })(Joosy.Function);
2618
+
2619
+ if ((typeof define !== "undefined" && define !== null ? define.amd : void 0) != null) {
2620
+ define('joosy/resources/scalar', function() {
2621
+ return Joosy.Resources.Scalar;
2473
2622
  });
2474
2623
  }
2475
2624
 
data/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "keywords": [
5
5
  "joosy"
6
6
  ],
7
- "version": "1.2.0-alpha.70",
7
+ "version": "1.2.0-alpha.71",
8
8
  "author": "Boris Staal <boris@staal.io>",
9
9
  "homepage": "http://joosy.ws/",
10
10
  "repository": {
@@ -15,8 +15,7 @@
15
15
  "node": ">=0.4.0"
16
16
  },
17
17
  "dependencies": {
18
- "grill": ">=1.0.0-alpha.19",
19
- "moment": "~2.1.0"
18
+ "grill": ">=1.0.0-alpha.19"
20
19
  },
21
20
  "devDependencies": {
22
21
  "bower": "~1.2.1",
@@ -24,6 +23,7 @@
24
23
  "grunt-coffeelint": "0.0.6",
25
24
  "grunt-release": "~0.3.5",
26
25
  "grunt-contrib-testem": ">=0.5.2",
27
- "grunt-gh-pages": "git+https://github.com/inossidabile/grunt-gh-pages.git"
26
+ "grunt-gh-pages": "git+https://github.com/inossidabile/grunt-gh-pages.git",
27
+ "moment": "~2.1.0"
28
28
  }
29
29
  }
@@ -1,5 +1,4 @@
1
1
  #= require joosy/joosy
2
- #= require_tree ../events
3
2
 
4
3
  # @private
5
4
  class SynchronizationContext
@@ -7,6 +6,35 @@ class SynchronizationContext
7
6
  do: (action) -> @actions.push action
8
7
  after: (@after) ->
9
8
 
9
+ #
10
+ # @private
11
+ # Events namespace
12
+ #
13
+ # Creates unified collection of bindings to a particular instance
14
+ # that can be unbinded alltogether
15
+ #
16
+ # @example
17
+ # namespace = new Namespace(something)
18
+ #
19
+ # namespace.bind 'event1', ->
20
+ # namespace.bind 'event2', ->
21
+ # namespace.unbind() # unbinds both bindings
22
+ #
23
+ class Namespace
24
+ #
25
+ # @param [Object] @parent Any instance that can trigger events
26
+ #
27
+ constructor: (@parent) ->
28
+ @bindings = []
29
+
30
+ bind: (args...) ->
31
+ @bindings.push @parent.bind(args...)
32
+
33
+ unbind: ->
34
+ @parent.unbind b for b in @bindings
35
+ @bindings = []
36
+
37
+
10
38
  #
11
39
  # Basic events implementation
12
40
  #
@@ -14,6 +42,21 @@ class SynchronizationContext
14
42
  #
15
43
  Joosy.Modules.Events =
16
44
 
45
+ #
46
+ # Creates events namespace
47
+ #
48
+ # @example
49
+ # namespace = @entity.eventsNamespace, ->
50
+ # @bind 'action1', ->
51
+ # @bind 'action2', ->
52
+ #
53
+ # namespace.unbind()
54
+ #
55
+ eventsNamespace: (actions) ->
56
+ namespace = new Namespace @
57
+ actions?.call?(namespace)
58
+ namespace
59
+
17
60
  #
18
61
  # Waits for the list of given events to happen at least once. Then runs callback.
19
62
  #
@@ -1,5 +1,7 @@
1
+ #= require ../page
2
+
1
3
  # @mixin
2
- Joosy.Modules.Page_Scrolling =
4
+ Joosy.Modules.Page.Scrolling =
3
5
 
4
6
  included: ->
5
7
  #
@@ -1,5 +1,7 @@
1
+ #= require ../page
2
+
1
3
  # @mixin
2
- Joosy.Modules.Page_Title =
4
+ Joosy.Modules.Page.Title =
3
5
 
4
6
  #
5
7
  # Sets the page HTML title.
@@ -0,0 +1 @@
1
+ Joosy.Modules.Page = {}
@@ -11,8 +11,8 @@
11
11
  # class @RumbaPage extends Joosy.Page
12
12
  # @view 'rumba'
13
13
  #
14
- # @include Joosy.Modules.Page_Scrolling
15
- # @extend Joosy.Modules.Page_Title
14
+ # @include Joosy.Modules.Page.Scrolling
15
+ # @extend Joosy.Modules.Page.Title
16
16
  #
17
17
  class Joosy.Page extends Joosy.Widget
18
18
  #
@@ -23,8 +23,8 @@ class Joosy.Page extends Joosy.Widget
23
23
  @layout: (layoutClass) ->
24
24
  @::__layoutClass = layoutClass
25
25
 
26
- @include Joosy.Modules.Page_Scrolling
27
- @extend Joosy.Modules.Page_Title
26
+ @include Joosy.Modules.Page.Scrolling
27
+ @extend Joosy.Modules.Page.Title
28
28
 
29
29
  #
30
30
  # @param [Hash] params Route params
@@ -1,9 +1,12 @@
1
1
  class Joosy.Resources.Array extends Array
2
2
 
3
3
  Joosy.Module.include.call @, Joosy.Modules.Events
4
+ Joosy.Module.include.call @, Joosy.Modules.Filters
5
+
6
+ @registerPlainFilters 'beforeLoad'
4
7
 
5
8
  constructor: ->
6
- @push entry for entry in @slice.call(arguments, 0)
9
+ @__fillData arguments, false
7
10
 
8
11
  get: (index) ->
9
12
  @[index]
@@ -11,7 +14,10 @@ class Joosy.Resources.Array extends Array
11
14
  set: (index, value) ->
12
15
  @[index] = value
13
16
  @trigger 'changed'
14
- @length
17
+ value
18
+
19
+ load: ->
20
+ @__fillData arguments
15
21
 
16
22
  push: ->
17
23
  result = super
@@ -38,6 +44,19 @@ class Joosy.Resources.Array extends Array
38
44
  @trigger 'changed'
39
45
  result
40
46
 
47
+ __fillData: (data, notify=true) ->
48
+ data = if data[0] instanceof Array
49
+ data[0]
50
+ else
51
+ @slice.call(data, 0)
52
+
53
+ @splice 0, @length if @length > 0
54
+ @push entry for entry in @__applyBeforeLoads(data)
55
+
56
+ @trigger 'changed' if notify
57
+
58
+ null
59
+
41
60
  # AMD wrapper
42
61
  if define?.amd?
43
62
  define 'joosy/resources/array', -> Joosy.Resources.Array
@@ -1,4 +1,4 @@
1
- class Joosy.Resources.Watcher extends Joosy.Module
1
+ class Joosy.Resources.Cacher extends Joosy.Module
2
2
 
3
3
  @include Joosy.Modules.Events
4
4
  @include Joosy.Modules.Filters
@@ -38,4 +38,4 @@ class Joosy.Resources.Watcher extends Joosy.Module
38
38
 
39
39
  # AMD wrapper
40
40
  if define?.amd?
41
- define 'joosy/resources/watcher', -> Joosy.Resources.Watcher
41
+ define 'joosy/resources/cacher', -> Joosy.Resources.Cacher
@@ -0,0 +1,83 @@
1
+ class Joosy.Resources.Hash extends Joosy.Function
2
+
3
+ @include Joosy.Modules.Events
4
+ @include Joosy.Modules.Filters
5
+
6
+ constructor: (data={}) ->
7
+ return super ->
8
+ @__fillData data, false
9
+
10
+ get: (path) ->
11
+ [instance, property] = @__callTarget path, true
12
+
13
+ return undefined unless instance
14
+
15
+ if instance instanceof Joosy.Resources.Hash
16
+ instance property
17
+ else
18
+ instance[property]
19
+
20
+ set: (path, value) ->
21
+ [instance, property] = @__callTarget path
22
+
23
+ if instance instanceof Joosy.Resources.Hash
24
+ instance(property, value)
25
+ else
26
+ instance[property] = value
27
+
28
+ @trigger 'changed'
29
+ value
30
+
31
+ load: (data) ->
32
+ @__fillData data
33
+ @
34
+
35
+ __call: (path, value) ->
36
+ if arguments.length > 1
37
+ @__set path, value
38
+ else
39
+ @__get path
40
+
41
+ #
42
+ # Locates the actual instance of attribute path `foo.bar` from get/set
43
+ #
44
+ # @param [String] path Path to the attribute (`foo.bar`)
45
+ # @param [Boolean] safe Indicates whether nested hashes should not be automatically created when they don't exist
46
+ # @return [Array] Instance of object containing last step of path and keyword for required field
47
+ #
48
+ __callTarget: (path, safe=false) ->
49
+ if path.indexOf('.') != -1 && !@data[path]?
50
+ path = path.split '.'
51
+ keyword = path.pop()
52
+ target = @data
53
+
54
+ for part in path
55
+ return false if safe && !target[part]?
56
+
57
+ target[part] ?= {}
58
+
59
+ target = if target instanceof Joosy.Resources.Hash
60
+ target(part)
61
+ else
62
+ target[part]
63
+
64
+ [target, keyword]
65
+ else
66
+ [@data, path]
67
+
68
+ #
69
+ # Defines how exactly prepared data should be saved
70
+ #
71
+ # @param [Object] data Raw data to store
72
+ #
73
+ __fillData: (data, notify=true) ->
74
+ @data = @__applyBeforeLoads data
75
+ @trigger 'changed' if notify
76
+ null
77
+
78
+ toString: ->
79
+ JSON.stringify(@data)
80
+
81
+ # AMD wrapper
82
+ if define?.amd?
83
+ define 'joosy/resources/hash', -> Joosy.Resources.Hash
@@ -1,23 +1,29 @@
1
1
  class Joosy.Resources.Scalar extends Joosy.Function
2
2
 
3
3
  @include Joosy.Modules.Events
4
+ @include Joosy.Modules.Filters
4
5
 
5
6
  constructor: (value) ->
6
7
  return super ->
7
8
  @value = value
8
9
 
10
+ get: ->
11
+ @value
12
+
13
+ set: ->
14
+ @load arguments...
15
+
16
+ load: (value) ->
17
+ @value = @__applyBeforeLoads(value)
18
+ @trigger 'changed'
19
+ @value
20
+
9
21
  __call: ->
10
22
  if arguments.length > 0
11
23
  @set arguments[0]
12
24
  else
13
25
  @get()
14
26
 
15
- get: ->
16
- @value
17
-
18
- set: (@value) ->
19
- @trigger 'changed'
20
-
21
27
  valueOf: ->
22
28
  @value.valueOf()
23
29
 
@@ -153,14 +153,14 @@ describe "Joosy.Modules.Events", ->
153
153
 
154
154
  waits 3
155
155
 
156
- describe "namespece", ->
156
+ describe "namespace", ->
157
157
 
158
158
  beforeEach ->
159
159
  @callback = sinon.spy()
160
160
 
161
161
  it "proxies events", ->
162
162
  eventer = new @Eventer
163
- namespace = new Joosy.Events.Namespace(eventer)
163
+ namespace = eventer.eventsNamespace()
164
164
 
165
165
  namespace.bind 'event1', @callback
166
166
  namespace.bind 'event2', @callback
@@ -170,9 +170,21 @@ describe "Joosy.Modules.Events", ->
170
170
 
171
171
  expect(@callback.callCount).toEqual 2
172
172
 
173
+ it "assigns with callback", ->
174
+ callback = @callback
175
+ eventer = new @Eventer
176
+ namespace = eventer.eventsNamespace ->
177
+ @bind 'event1', callback
178
+ @bind 'event2', callback
179
+
180
+ eventer.trigger 'event1'
181
+ eventer.trigger 'event2'
182
+
183
+ expect(@callback.callCount).toEqual 2
184
+
173
185
  it "unbinds events", ->
174
186
  eventer = new @Eventer
175
- namespace = new Joosy.Events.Namespace(eventer)
187
+ namespace = eventer.eventsNamespace()
176
188
 
177
189
  namespace.bind 'event1', @callback
178
190
  namespace.bind 'event2', @callback
@@ -32,8 +32,9 @@ describe "Joosy", ->
32
32
  'joosy/modules/time_manager',
33
33
  'joosy/page',
34
34
  'joosy/resources/array',
35
+ 'joosy/resources/cacher',
36
+ 'joosy/resources/hash',
35
37
  'joosy/resources/scalar',
36
- 'joosy/resources/watcher',
37
38
  'joosy/router',
38
39
  'joosy/templaters/jst',
39
40
  'joosy/widget'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: joosy
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0.alpha.70
4
+ version: 1.2.0.alpha.71
5
5
  platform: ruby
6
6
  authors:
7
7
  - Boris Staal
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-09-02 00:00:00.000000000 Z
13
+ date: 2013-09-03 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: sprockets
@@ -60,7 +60,6 @@ files:
60
60
  - package.json
61
61
  - source/joosy.coffee
62
62
  - source/joosy/application.coffee
63
- - source/joosy/events/namespace.coffee
64
63
  - source/joosy/extensions/resources-form/form.coffee
65
64
  - source/joosy/extensions/resources-form/helpers/form.coffee
66
65
  - source/joosy/extensions/resources-form/index.coffee
@@ -79,6 +78,7 @@ files:
79
78
  - source/joosy/modules/events.coffee
80
79
  - source/joosy/modules/filters.coffee
81
80
  - source/joosy/modules/log.coffee
81
+ - source/joosy/modules/page.coffee
82
82
  - source/joosy/modules/page/scrolling.coffee
83
83
  - source/joosy/modules/page/title.coffee
84
84
  - source/joosy/modules/renderer.coffee
@@ -86,8 +86,9 @@ files:
86
86
  - source/joosy/modules/widgets_manager.coffee
87
87
  - source/joosy/page.coffee
88
88
  - source/joosy/resources/array.coffee
89
+ - source/joosy/resources/cacher.coffee
90
+ - source/joosy/resources/hash.coffee
89
91
  - source/joosy/resources/scalar.coffee
90
- - source/joosy/resources/watcher.coffee
91
92
  - source/joosy/router.coffee
92
93
  - source/joosy/templaters/jst.coffee
93
94
  - source/joosy/widget.coffee
@@ -1,25 +0,0 @@
1
- #
2
- # Events namespace
3
- #
4
- # Creates unified collection of bindings to a particular instance
5
- # that can be unbinded alltogether
6
- #
7
- # @see Joosy.Modules.Events
8
- # @example
9
- # namespace = Joosy.Events.Namespace(something)
10
- #
11
- # namespace.bind 'event1', ->
12
- # namespace.bind 'event2', ->
13
- # namespace.unbind() # unbinds both bindings
14
- #
15
- class Joosy.Events.Namespace
16
- #
17
- # @param [Object] @parent Any instance that can trigger events
18
- #
19
- constructor: (@parent) ->
20
- @bindings = []
21
-
22
- bind: (args...) -> @bindings.push @parent.bind(args...)
23
- unbind: ->
24
- @parent.unbind b for b in @bindings
25
- @bindings = []