joosy 1.2.0.alpha.71 → 1.2.0.alpha.73
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 +4 -4
- data/bower.json +1 -1
- data/build/joosy/extensions/resources-form.js +5 -6
- data/build/joosy/extensions/resources.js +69 -244
- data/build/joosy.js +109 -90
- data/package.json +1 -1
- data/source/joosy/extensions/resources/base.coffee +2 -20
- data/source/joosy/extensions/resources/rest.coffee +63 -38
- data/source/joosy/extensions/resources-form/form.coffee +3 -3
- data/source/joosy/modules/resources/cacher.coffee +38 -0
- data/source/joosy/modules/resources.coffee +1 -0
- data/source/joosy/resources/array.coffee +12 -6
- data/source/joosy/resources/hash.coffee +9 -2
- data/source/joosy/resources/scalar.coffee +10 -3
- data/spec/joosy/core/modules/resources/cacher_spec.coffee +81 -0
- data/spec/joosy/core/resources/array_spec.coffee +60 -0
- data/spec/joosy/core/resources/hash_spec.coffee +58 -0
- data/spec/joosy/core/resources/scalar_spec.coffee +41 -0
- data/spec/joosy/environments/amd_spec.coffee +1 -1
- data/spec/joosy/extensions/form/form_spec.coffee +2 -2
- data/spec/joosy/extensions/resources/base_spec.coffee +2 -37
- data/spec/joosy/extensions/resources/rest_spec.coffee +10 -10
- metadata +8 -7
- data/source/joosy/extensions/resources/collection.coffee +0 -178
- data/source/joosy/extensions/resources/rest_collection.coffee +0 -33
- data/source/joosy/resources/cacher.coffee +0 -41
- data/spec/joosy/extensions/resources/collection_spec.coffee +0 -92
- data/spec/joosy/extensions/resources/rest_collection_spec.coffee +0 -41
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c93a94e26133a7f31ce8568c0f30123014c392ec
|
4
|
+
data.tar.gz: 8d69ccc6b80a2da510a272e1bda09b543a79a49a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 57cead0f12f2bc1e652e723247688a78ed4bcf842d657d9396e9a13b8bc7bd90ea524f2f868be2a570c114a6601e7907fc2c7f5892ef389022170144791639af
|
7
|
+
data.tar.gz: 477925bb13b147ad0d52a822262bc20cbfda09d687dc1125e571cf4afd8c738234cf30fcedc1618437f71dbdf82ae035b047cad0b598f2e3bafb2b08c60f7da1
|
data/bower.json
CHANGED
@@ -130,7 +130,7 @@
|
|
130
130
|
}
|
131
131
|
data.__joosy_form_filler_lock = true;
|
132
132
|
Object.each(data, function(property, val) {
|
133
|
-
var entity, i, input, key, _i, _len,
|
133
|
+
var entity, i, input, key, _i, _len, _results;
|
134
134
|
key = _this.concatFieldName(scope, property);
|
135
135
|
input = _this.$fields().filter("[name='" + key + "']:not(:file),[name='" + (key.underscore()) + "']:not(:file),[name='" + (key.camelize(false)) + "']:not(:file)");
|
136
136
|
if (input.length > 0) {
|
@@ -146,16 +146,15 @@
|
|
146
146
|
input.val(val);
|
147
147
|
}
|
148
148
|
}
|
149
|
-
if (val instanceof Joosy.Resources.
|
150
|
-
_ref = val.data;
|
149
|
+
if (val instanceof Joosy.Resources.Array) {
|
151
150
|
_results = [];
|
152
|
-
for (i = _i = 0, _len =
|
153
|
-
entity =
|
151
|
+
for (i = _i = 0, _len = val.length; _i < _len; i = ++_i) {
|
152
|
+
entity = val[i];
|
154
153
|
_results.push(filler(entity.data, _this.concatFieldName(scope, "[" + property + "_attributes][" + i + "]")));
|
155
154
|
}
|
156
155
|
return _results;
|
157
156
|
} else if (val instanceof Joosy.Resources.REST) {
|
158
|
-
return filler(val.data, _this.concatFieldName(scope, "[" + property + "_attributes]
|
157
|
+
return filler(val.data, _this.concatFieldName(scope, "[" + property + "_attributes]"));
|
159
158
|
} else if (Object.isObject(val) || Object.isArray(val)) {
|
160
159
|
return filler(val, key);
|
161
160
|
} else {
|
@@ -27,22 +27,6 @@
|
|
27
27
|
return this.prototype.__entityName = name;
|
28
28
|
};
|
29
29
|
|
30
|
-
Base.collection = function(klass) {
|
31
|
-
return this.prototype.__collection = function() {
|
32
|
-
return klass;
|
33
|
-
};
|
34
|
-
};
|
35
|
-
|
36
|
-
Base.prototype.__collection = function() {
|
37
|
-
var named;
|
38
|
-
named = this.__entityName.camelize().pluralize() + 'Collection';
|
39
|
-
if (window[named]) {
|
40
|
-
return window[named];
|
41
|
-
} else {
|
42
|
-
return Joosy.Resources.Collection;
|
43
|
-
}
|
44
|
-
};
|
45
|
-
|
46
30
|
Base.map = function(name, klass) {
|
47
31
|
if (klass == null) {
|
48
32
|
klass = false;
|
@@ -228,11 +212,16 @@
|
|
228
212
|
};
|
229
213
|
|
230
214
|
Base.prototype.__map = function(data, name, klass) {
|
231
|
-
var
|
215
|
+
var entries;
|
232
216
|
if (Object.isArray(data[name])) {
|
233
|
-
|
234
|
-
|
235
|
-
|
217
|
+
entries = data[name].map(function(x) {
|
218
|
+
return klass.build(x);
|
219
|
+
});
|
220
|
+
data[name] = (function(func, args, ctor) {
|
221
|
+
ctor.prototype = func.prototype;
|
222
|
+
var child = new ctor, result = func.apply(child, args);
|
223
|
+
return Object(result) === result ? result : child;
|
224
|
+
})(Joosy.Resources.Array, entries, function(){});
|
236
225
|
} else if (Object.isObject(data[name])) {
|
237
226
|
data[name] = klass.build(data[name]);
|
238
227
|
}
|
@@ -247,191 +236,6 @@
|
|
247
236
|
|
248
237
|
})(Joosy.Function);
|
249
238
|
|
250
|
-
}).call(this);
|
251
|
-
(function() {
|
252
|
-
var __hasProp = {}.hasOwnProperty,
|
253
|
-
__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; },
|
254
|
-
__slice = [].slice;
|
255
|
-
|
256
|
-
Joosy.Resources.Collection = (function(_super) {
|
257
|
-
__extends(Collection, _super);
|
258
|
-
|
259
|
-
Collection.include(Joosy.Modules.Events);
|
260
|
-
|
261
|
-
Collection.beforeLoad = function(action) {
|
262
|
-
return this.prototype.__beforeLoad = action;
|
263
|
-
};
|
264
|
-
|
265
|
-
Collection.model = function(model) {
|
266
|
-
return this.prototype.model = model;
|
267
|
-
};
|
268
|
-
|
269
|
-
function Collection(model, findOptions) {
|
270
|
-
if (model == null) {
|
271
|
-
model = false;
|
272
|
-
}
|
273
|
-
this.findOptions = findOptions;
|
274
|
-
if (model) {
|
275
|
-
this.model = model;
|
276
|
-
}
|
277
|
-
this.data = [];
|
278
|
-
if (!this.model) {
|
279
|
-
throw new Error("" + (Joosy.Module.__className(this)) + "> model can't be empty");
|
280
|
-
}
|
281
|
-
}
|
282
|
-
|
283
|
-
Collection.prototype.load = function(entities, notify) {
|
284
|
-
if (notify == null) {
|
285
|
-
notify = true;
|
286
|
-
}
|
287
|
-
if (this.__beforeLoad != null) {
|
288
|
-
entities = this.__beforeLoad(entities);
|
289
|
-
}
|
290
|
-
this.data = this.modelize(entities);
|
291
|
-
if (notify) {
|
292
|
-
this.trigger('changed');
|
293
|
-
}
|
294
|
-
return this;
|
295
|
-
};
|
296
|
-
|
297
|
-
Collection.prototype.modelize = function(collection) {
|
298
|
-
var root,
|
299
|
-
_this = this;
|
300
|
-
root = this.model.prototype.__entityName.pluralize();
|
301
|
-
if (!(collection instanceof Array)) {
|
302
|
-
collection = collection != null ? collection[root.camelize(false)] : void 0;
|
303
|
-
if (!(collection instanceof Array)) {
|
304
|
-
throw new Error("Can not read incoming JSON");
|
305
|
-
}
|
306
|
-
}
|
307
|
-
return collection.map(function(x) {
|
308
|
-
return _this.model.build(x);
|
309
|
-
});
|
310
|
-
};
|
311
|
-
|
312
|
-
Collection.prototype.each = function(callback) {
|
313
|
-
return this.data.each(callback);
|
314
|
-
};
|
315
|
-
|
316
|
-
Collection.prototype.size = function() {
|
317
|
-
return this.data.length;
|
318
|
-
};
|
319
|
-
|
320
|
-
Collection.prototype.find = function(description) {
|
321
|
-
return this.data.find(description);
|
322
|
-
};
|
323
|
-
|
324
|
-
Collection.prototype.sortBy = function() {
|
325
|
-
var params, _ref;
|
326
|
-
params = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
|
327
|
-
return (_ref = this.data).sortBy.apply(_ref, params);
|
328
|
-
};
|
329
|
-
|
330
|
-
Collection.prototype.findById = function(id) {
|
331
|
-
return this.data.find(function(x) {
|
332
|
-
return x.id().toString() === id.toString();
|
333
|
-
});
|
334
|
-
};
|
335
|
-
|
336
|
-
Collection.prototype.at = function(i) {
|
337
|
-
return this.data[i];
|
338
|
-
};
|
339
|
-
|
340
|
-
Collection.prototype.remove = function(target, notify) {
|
341
|
-
var index, result;
|
342
|
-
if (notify == null) {
|
343
|
-
notify = true;
|
344
|
-
}
|
345
|
-
if (Object.isNumber(target)) {
|
346
|
-
index = target;
|
347
|
-
} else {
|
348
|
-
index = this.data.indexOf(target);
|
349
|
-
}
|
350
|
-
if (index >= 0) {
|
351
|
-
result = this.data.splice(index, 1)[0];
|
352
|
-
if (notify) {
|
353
|
-
this.trigger('changed');
|
354
|
-
}
|
355
|
-
}
|
356
|
-
return result;
|
357
|
-
};
|
358
|
-
|
359
|
-
Collection.prototype.add = function(element, index, notify) {
|
360
|
-
if (index == null) {
|
361
|
-
index = false;
|
362
|
-
}
|
363
|
-
if (notify == null) {
|
364
|
-
notify = true;
|
365
|
-
}
|
366
|
-
if (typeof index === 'number') {
|
367
|
-
this.data.splice(index, 0, element);
|
368
|
-
} else {
|
369
|
-
this.data.push(element);
|
370
|
-
}
|
371
|
-
if (notify) {
|
372
|
-
this.trigger('changed');
|
373
|
-
}
|
374
|
-
return element;
|
375
|
-
};
|
376
|
-
|
377
|
-
return Collection;
|
378
|
-
|
379
|
-
})(Joosy.Module);
|
380
|
-
|
381
|
-
}).call(this);
|
382
|
-
(function() {
|
383
|
-
var _ref,
|
384
|
-
__hasProp = {}.hasOwnProperty,
|
385
|
-
__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; },
|
386
|
-
__slice = [].slice;
|
387
|
-
|
388
|
-
Joosy.Resources.RESTCollection = (function(_super) {
|
389
|
-
__extends(RESTCollection, _super);
|
390
|
-
|
391
|
-
function RESTCollection() {
|
392
|
-
_ref = RESTCollection.__super__.constructor.apply(this, arguments);
|
393
|
-
return _ref;
|
394
|
-
}
|
395
|
-
|
396
|
-
RESTCollection.include(Joosy.Modules.Log);
|
397
|
-
|
398
|
-
RESTCollection.include(Joosy.Modules.Events);
|
399
|
-
|
400
|
-
RESTCollection.prototype.reload = function(options, callback) {
|
401
|
-
var _this = this;
|
402
|
-
if (options == null) {
|
403
|
-
options = {};
|
404
|
-
}
|
405
|
-
if (callback == null) {
|
406
|
-
callback = false;
|
407
|
-
}
|
408
|
-
if (Object.isFunction(options)) {
|
409
|
-
callback = options;
|
410
|
-
options = {};
|
411
|
-
}
|
412
|
-
return this.model.__query(this.model.collectionPath(options, this.__source), 'GET', options.params, function(error, data, xhr) {
|
413
|
-
if (data != null) {
|
414
|
-
_this.load(data);
|
415
|
-
}
|
416
|
-
return typeof callback === "function" ? callback(error, _this, data, xhr) : void 0;
|
417
|
-
});
|
418
|
-
};
|
419
|
-
|
420
|
-
RESTCollection.prototype.load = function() {
|
421
|
-
var args, res,
|
422
|
-
_this = this;
|
423
|
-
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
|
424
|
-
res = RESTCollection.__super__.load.apply(this, args);
|
425
|
-
this.data.each(function(x) {
|
426
|
-
return x.__source = _this.__source;
|
427
|
-
});
|
428
|
-
return res;
|
429
|
-
};
|
430
|
-
|
431
|
-
return RESTCollection;
|
432
|
-
|
433
|
-
})(Joosy.Resources.Collection);
|
434
|
-
|
435
239
|
}).call(this);
|
436
240
|
(function() {
|
437
241
|
var _ref,
|
@@ -499,16 +303,6 @@
|
|
499
303
|
return new ((_ref1 = this.constructor).at.apply(_ref1, args))(this.data);
|
500
304
|
};
|
501
305
|
|
502
|
-
REST.prototype.__collection = function() {
|
503
|
-
var named;
|
504
|
-
named = this.__entityName.camelize().pluralize() + 'Collection';
|
505
|
-
if (window[named]) {
|
506
|
-
return window[named];
|
507
|
-
} else {
|
508
|
-
return Joosy.Resources.RESTCollection;
|
509
|
-
}
|
510
|
-
};
|
511
|
-
|
512
306
|
REST.prototype.__interpolatePath = function(source, ids) {
|
513
307
|
if (!Object.isArray(ids)) {
|
514
308
|
ids = [ids];
|
@@ -642,8 +436,26 @@
|
|
642
436
|
return this.constructor.__query(this.memberPath(options), 'DELETE', options.params, callback);
|
643
437
|
};
|
644
438
|
|
439
|
+
REST.prototype.reload = function(options, callback) {
|
440
|
+
var _ref1,
|
441
|
+
_this = this;
|
442
|
+
if (options == null) {
|
443
|
+
options = {};
|
444
|
+
}
|
445
|
+
if (callback == null) {
|
446
|
+
callback = false;
|
447
|
+
}
|
448
|
+
_ref1 = this.__extractOptionsAndCallback(options, callback), options = _ref1[0], callback = _ref1[1];
|
449
|
+
return this.constructor.__query(this.memberPath(options), 'GET', options.params, function(error, data, xhr) {
|
450
|
+
if (data != null) {
|
451
|
+
_this.load(data);
|
452
|
+
}
|
453
|
+
return typeof callback === "function" ? callback(error, _this, data, xhr) : void 0;
|
454
|
+
});
|
455
|
+
};
|
456
|
+
|
645
457
|
REST.find = function(where, options, callback) {
|
646
|
-
var id,
|
458
|
+
var id, result, _ref1,
|
647
459
|
_this = this;
|
648
460
|
if (options == null) {
|
649
461
|
options = {};
|
@@ -652,18 +464,12 @@
|
|
652
464
|
callback = false;
|
653
465
|
}
|
654
466
|
_ref1 = this.prototype.__extractOptionsAndCallback(options, callback), options = _ref1[0], callback = _ref1[1];
|
655
|
-
id =
|
656
|
-
|
657
|
-
|
658
|
-
path = this.collectionPath(where, options);
|
659
|
-
} else {
|
660
|
-
result = this.build(id);
|
661
|
-
path = this.memberPath(where, options);
|
662
|
-
}
|
663
|
-
if (Object.isArray(where) && where.length > 1) {
|
467
|
+
id = where instanceof Array ? where[where.length - 1] : where;
|
468
|
+
result = this.build(id);
|
469
|
+
if (where instanceof Array && where.length > 1) {
|
664
470
|
result.__source = this.collectionPath(where);
|
665
471
|
}
|
666
|
-
this.__query(
|
472
|
+
this.__query(this.memberPath(where, options), 'GET', options.params, function(error, data, xhr) {
|
667
473
|
if (data != null) {
|
668
474
|
result.load(data);
|
669
475
|
}
|
@@ -672,6 +478,43 @@
|
|
672
478
|
return result;
|
673
479
|
};
|
674
480
|
|
481
|
+
REST.all = function(where, options, callback) {
|
482
|
+
var result, _ref1, _ref2,
|
483
|
+
_this = this;
|
484
|
+
if (options == null) {
|
485
|
+
options = {};
|
486
|
+
}
|
487
|
+
if (callback == null) {
|
488
|
+
callback = false;
|
489
|
+
}
|
490
|
+
if (Object.isFunction(where) || Object.isObject(where)) {
|
491
|
+
_ref1 = this.prototype.__extractOptionsAndCallback(where, options), options = _ref1[0], callback = _ref1[1];
|
492
|
+
where = [];
|
493
|
+
} else {
|
494
|
+
_ref2 = this.prototype.__extractOptionsAndCallback(options, callback), options = _ref2[0], callback = _ref2[1];
|
495
|
+
}
|
496
|
+
result = new Joosy.Resources.Array;
|
497
|
+
this.__query(this.collectionPath(where, options), 'GET', options.params, function(error, rawData, xhr) {
|
498
|
+
var data;
|
499
|
+
if ((data = rawData) != null) {
|
500
|
+
if (Object.isObject(data) && !(data = data[_this.prototype.__entityName.pluralize()])) {
|
501
|
+
throw new Error("Invalid data for `all` received: " + (JSON.stringify(data)));
|
502
|
+
}
|
503
|
+
data = data.map(function(x) {
|
504
|
+
var instance;
|
505
|
+
instance = _this.build(x);
|
506
|
+
if (where.length > 1) {
|
507
|
+
instance.__source = _this.collectionPath(where);
|
508
|
+
}
|
509
|
+
return instance;
|
510
|
+
});
|
511
|
+
result.load.apply(result, data);
|
512
|
+
}
|
513
|
+
return typeof callback === "function" ? callback(error, result, rawData, xhr) : void 0;
|
514
|
+
});
|
515
|
+
return result;
|
516
|
+
};
|
517
|
+
|
675
518
|
REST.__query = function(path, method, params, callback) {
|
676
519
|
var options;
|
677
520
|
options = {
|
@@ -699,24 +542,6 @@
|
|
699
542
|
return $.ajax(options);
|
700
543
|
};
|
701
544
|
|
702
|
-
REST.prototype.reload = function(options, callback) {
|
703
|
-
var _ref1,
|
704
|
-
_this = this;
|
705
|
-
if (options == null) {
|
706
|
-
options = {};
|
707
|
-
}
|
708
|
-
if (callback == null) {
|
709
|
-
callback = false;
|
710
|
-
}
|
711
|
-
_ref1 = this.__extractOptionsAndCallback(options, callback), options = _ref1[0], callback = _ref1[1];
|
712
|
-
return this.constructor.__query(this.memberPath(options), 'GET', options.params, function(error, data, xhr) {
|
713
|
-
if (data != null) {
|
714
|
-
_this.load(data);
|
715
|
-
}
|
716
|
-
return typeof callback === "function" ? callback(error, _this, data, xhr) : void 0;
|
717
|
-
});
|
718
|
-
};
|
719
|
-
|
720
545
|
REST.prototype.__extractOptionsAndCallback = function(options, callback) {
|
721
546
|
if (Object.isFunction(options)) {
|
722
547
|
callback = options;
|
data/build/joosy.js
CHANGED
@@ -2276,6 +2276,85 @@
|
|
2276
2276
|
});
|
2277
2277
|
}
|
2278
2278
|
|
2279
|
+
}).call(this);
|
2280
|
+
(function() {
|
2281
|
+
Joosy.Modules.Resources = {};
|
2282
|
+
|
2283
|
+
}).call(this);
|
2284
|
+
(function() {
|
2285
|
+
var __slice = [].slice;
|
2286
|
+
|
2287
|
+
Joosy.Modules.Resources.Cacher = {
|
2288
|
+
included: function() {
|
2289
|
+
this.cache = function(cacheKey) {
|
2290
|
+
return this.prototype.__cacheKey = cacheKey;
|
2291
|
+
};
|
2292
|
+
this.fetcher = function(fetcher) {
|
2293
|
+
return this.prototype.__fetcher = fetcher;
|
2294
|
+
};
|
2295
|
+
this.cached = function(callback, cacheKey, fetcher) {
|
2296
|
+
var instance,
|
2297
|
+
_this = this;
|
2298
|
+
if (cacheKey == null) {
|
2299
|
+
cacheKey = false;
|
2300
|
+
}
|
2301
|
+
if (fetcher == null) {
|
2302
|
+
fetcher = false;
|
2303
|
+
}
|
2304
|
+
if (typeof cacheKey === 'function') {
|
2305
|
+
fetcher = cacheKey;
|
2306
|
+
cacheKey = void 0;
|
2307
|
+
}
|
2308
|
+
cacheKey || (cacheKey = this.prototype.__cacheKey);
|
2309
|
+
fetcher || (fetcher = this.prototype.__fetcher);
|
2310
|
+
if (cacheKey && localStorage && localStorage[cacheKey]) {
|
2311
|
+
instance = (function(func, args, ctor) {
|
2312
|
+
ctor.prototype = func.prototype;
|
2313
|
+
var child = new ctor, result = func.apply(child, args);
|
2314
|
+
return Object(result) === result ? result : child;
|
2315
|
+
})(this, JSON.parse(localStorage[cacheKey]), function(){});
|
2316
|
+
if (typeof callback === "function") {
|
2317
|
+
callback(instance);
|
2318
|
+
}
|
2319
|
+
return instance.refresh();
|
2320
|
+
} else {
|
2321
|
+
return this.fetch(function(results) {
|
2322
|
+
instance = (function(func, args, ctor) {
|
2323
|
+
ctor.prototype = func.prototype;
|
2324
|
+
var child = new ctor, result = func.apply(child, args);
|
2325
|
+
return Object(result) === result ? result : child;
|
2326
|
+
})(_this, results, function(){});
|
2327
|
+
return typeof callback === "function" ? callback(instance) : void 0;
|
2328
|
+
});
|
2329
|
+
}
|
2330
|
+
};
|
2331
|
+
return this.fetch = function(callback) {
|
2332
|
+
var _this = this;
|
2333
|
+
return this.prototype.__fetcher(function() {
|
2334
|
+
var results;
|
2335
|
+
results = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
|
2336
|
+
if (_this.prototype.__cacheKey && localStorage) {
|
2337
|
+
localStorage[_this.prototype.__cacheKey] = JSON.stringify(results);
|
2338
|
+
}
|
2339
|
+
return callback(results);
|
2340
|
+
});
|
2341
|
+
};
|
2342
|
+
},
|
2343
|
+
refresh: function(callback) {
|
2344
|
+
var _this = this;
|
2345
|
+
return this.constructor.fetch(function(results) {
|
2346
|
+
_this.load.apply(_this, results);
|
2347
|
+
return typeof callback === "function" ? callback(_this) : void 0;
|
2348
|
+
});
|
2349
|
+
}
|
2350
|
+
};
|
2351
|
+
|
2352
|
+
if ((typeof define !== "undefined" && define !== null ? define.amd : void 0) != null) {
|
2353
|
+
define('joosy/modules/resources/cacher', function() {
|
2354
|
+
return Joosy.Modules.Resources.Cacher;
|
2355
|
+
});
|
2356
|
+
}
|
2357
|
+
|
2279
2358
|
}).call(this);
|
2280
2359
|
(function() {
|
2281
2360
|
var __hasProp = {}.hasOwnProperty,
|
@@ -2284,9 +2363,11 @@
|
|
2284
2363
|
Joosy.Resources.Array = (function(_super) {
|
2285
2364
|
__extends(Array, _super);
|
2286
2365
|
|
2287
|
-
Joosy.Module.
|
2366
|
+
Joosy.Module.merge(Array, Joosy.Module);
|
2367
|
+
|
2368
|
+
Array.include(Joosy.Modules.Events);
|
2288
2369
|
|
2289
|
-
|
2370
|
+
Array.include(Joosy.Modules.Filters);
|
2290
2371
|
|
2291
2372
|
Array.registerPlainFilters('beforeLoad');
|
2292
2373
|
|
@@ -2308,6 +2389,13 @@
|
|
2308
2389
|
return this.__fillData(arguments);
|
2309
2390
|
};
|
2310
2391
|
|
2392
|
+
Array.prototype.clone = function(callback) {
|
2393
|
+
var clone;
|
2394
|
+
clone = new this.constructor;
|
2395
|
+
clone.data = this.slice(0);
|
2396
|
+
return clone;
|
2397
|
+
};
|
2398
|
+
|
2311
2399
|
Array.prototype.push = function() {
|
2312
2400
|
var result;
|
2313
2401
|
result = Array.__super__.push.apply(this, arguments);
|
@@ -2348,7 +2436,7 @@
|
|
2348
2436
|
if (notify == null) {
|
2349
2437
|
notify = true;
|
2350
2438
|
}
|
2351
|
-
data =
|
2439
|
+
data = this.slice.call(data, 0);
|
2352
2440
|
if (this.length > 0) {
|
2353
2441
|
this.splice(0, this.length);
|
2354
2442
|
}
|
@@ -2373,88 +2461,6 @@
|
|
2373
2461
|
});
|
2374
2462
|
}
|
2375
2463
|
|
2376
|
-
}).call(this);
|
2377
|
-
(function() {
|
2378
|
-
var __hasProp = {}.hasOwnProperty,
|
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; };
|
2380
|
-
|
2381
|
-
Joosy.Resources.Cacher = (function(_super) {
|
2382
|
-
__extends(Cacher, _super);
|
2383
|
-
|
2384
|
-
Cacher.include(Joosy.Modules.Events);
|
2385
|
-
|
2386
|
-
Cacher.include(Joosy.Modules.Filters);
|
2387
|
-
|
2388
|
-
Cacher.registerPlainFilters('beforeLoad');
|
2389
|
-
|
2390
|
-
Cacher.cache = function(cacheKey) {
|
2391
|
-
return this.prototype.__cacheKey = cacheKey;
|
2392
|
-
};
|
2393
|
-
|
2394
|
-
Cacher.fetcher = function(fetcher) {
|
2395
|
-
return this.prototype.__fetcher = fetcher;
|
2396
|
-
};
|
2397
|
-
|
2398
|
-
function Cacher(callback, cacheKey, fetcher) {
|
2399
|
-
if (cacheKey == null) {
|
2400
|
-
cacheKey = false;
|
2401
|
-
}
|
2402
|
-
if (fetcher == null) {
|
2403
|
-
fetcher = false;
|
2404
|
-
}
|
2405
|
-
if (typeof cacheKey === 'function') {
|
2406
|
-
fetcher = cacheKey;
|
2407
|
-
cacheKey = void 0;
|
2408
|
-
}
|
2409
|
-
if (fetcher) {
|
2410
|
-
this.__fetcher = fetcher;
|
2411
|
-
}
|
2412
|
-
if (cacheKey) {
|
2413
|
-
this.__cacheKey = cacheKey;
|
2414
|
-
}
|
2415
|
-
if (this.__cacheKey && localStorage && localStorage[this.__cacheKey]) {
|
2416
|
-
this.data = this.__applyBeforeLoads(JSON.parse(localStorage[this.__cacheKey]));
|
2417
|
-
if (typeof callback === "function") {
|
2418
|
-
callback(this);
|
2419
|
-
}
|
2420
|
-
this.refresh();
|
2421
|
-
} else {
|
2422
|
-
this.refresh(callback);
|
2423
|
-
}
|
2424
|
-
}
|
2425
|
-
|
2426
|
-
Cacher.prototype.clone = function(callback) {
|
2427
|
-
var copy;
|
2428
|
-
copy = new this.constructor(callback, this.__cacheKey, this.__fetcher);
|
2429
|
-
copy.data = Object.clone(this.data, true);
|
2430
|
-
copy.trigger('changed');
|
2431
|
-
return copy;
|
2432
|
-
};
|
2433
|
-
|
2434
|
-
Cacher.prototype.refresh = function(callback) {
|
2435
|
-
var _this = this;
|
2436
|
-
return this.__fetcher(function(result) {
|
2437
|
-
if (_this.__cacheKey && localStorage) {
|
2438
|
-
localStorage[_this.__cacheKey] = JSON.stringify(result);
|
2439
|
-
}
|
2440
|
-
_this.data = _this.__applyBeforeLoads(result);
|
2441
|
-
if (typeof callback === "function") {
|
2442
|
-
callback(_this);
|
2443
|
-
}
|
2444
|
-
return _this.trigger('changed');
|
2445
|
-
});
|
2446
|
-
};
|
2447
|
-
|
2448
|
-
return Cacher;
|
2449
|
-
|
2450
|
-
})(Joosy.Module);
|
2451
|
-
|
2452
|
-
if ((typeof define !== "undefined" && define !== null ? define.amd : void 0) != null) {
|
2453
|
-
define('joosy/resources/cacher', function() {
|
2454
|
-
return Joosy.Resources.Cacher;
|
2455
|
-
});
|
2456
|
-
}
|
2457
|
-
|
2458
2464
|
}).call(this);
|
2459
2465
|
(function() {
|
2460
2466
|
var __hasProp = {}.hasOwnProperty,
|
@@ -2467,6 +2473,8 @@
|
|
2467
2473
|
|
2468
2474
|
Hash.include(Joosy.Modules.Filters);
|
2469
2475
|
|
2476
|
+
Hash.registerPlainFilters('beforeLoad');
|
2477
|
+
|
2470
2478
|
function Hash(data) {
|
2471
2479
|
if (data == null) {
|
2472
2480
|
data = {};
|
@@ -2506,11 +2514,15 @@
|
|
2506
2514
|
return this;
|
2507
2515
|
};
|
2508
2516
|
|
2517
|
+
Hash.prototype.clone = function(callback) {
|
2518
|
+
return new this.constructor(Object.clone(this.data, true));
|
2519
|
+
};
|
2520
|
+
|
2509
2521
|
Hash.prototype.__call = function(path, value) {
|
2510
2522
|
if (arguments.length > 1) {
|
2511
|
-
return this.
|
2523
|
+
return this.set(path, value);
|
2512
2524
|
} else {
|
2513
|
-
return this.
|
2525
|
+
return this.get(path);
|
2514
2526
|
}
|
2515
2527
|
};
|
2516
2528
|
|
@@ -2576,9 +2588,11 @@
|
|
2576
2588
|
|
2577
2589
|
Scalar.include(Joosy.Modules.Filters);
|
2578
2590
|
|
2591
|
+
Scalar.registerPlainFilters('beforeLoad');
|
2592
|
+
|
2579
2593
|
function Scalar(value) {
|
2580
2594
|
return Scalar.__super__.constructor.call(this, function() {
|
2581
|
-
return this.value
|
2595
|
+
return this.load(value);
|
2582
2596
|
});
|
2583
2597
|
}
|
2584
2598
|
|
@@ -2586,8 +2600,9 @@
|
|
2586
2600
|
return this.value;
|
2587
2601
|
};
|
2588
2602
|
|
2589
|
-
Scalar.prototype.set = function() {
|
2590
|
-
|
2603
|
+
Scalar.prototype.set = function(value) {
|
2604
|
+
this.value = value;
|
2605
|
+
return this.trigger('changed');
|
2591
2606
|
};
|
2592
2607
|
|
2593
2608
|
Scalar.prototype.load = function(value) {
|
@@ -2596,6 +2611,10 @@
|
|
2596
2611
|
return this.value;
|
2597
2612
|
};
|
2598
2613
|
|
2614
|
+
Scalar.prototype.clone = function(callback) {
|
2615
|
+
return new this.constructor(this.value);
|
2616
|
+
};
|
2617
|
+
|
2599
2618
|
Scalar.prototype.__call = function() {
|
2600
2619
|
if (arguments.length > 0) {
|
2601
2620
|
return this.set(arguments[0]);
|