ar_sync 1.0.3 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/test.yml +27 -0
  3. data/Gemfile +1 -0
  4. data/Gemfile.lock +29 -31
  5. data/ar_sync.gemspec +1 -1
  6. data/core/{ActioncableAdapter.d.ts → ActionCableAdapter.d.ts} +0 -0
  7. data/core/ActionCableAdapter.js +31 -0
  8. data/core/ArSyncApi.d.ts +8 -2
  9. data/core/ArSyncApi.js +123 -49
  10. data/core/ArSyncModel.js +69 -60
  11. data/core/ArSyncStore.js +522 -381
  12. data/core/ConnectionManager.d.ts +1 -1
  13. data/core/ConnectionManager.js +45 -38
  14. data/core/DataType.d.ts +14 -9
  15. data/core/hooks.d.ts +5 -0
  16. data/core/hooks.js +64 -36
  17. data/gemfiles/Gemfile-rails-6 +9 -0
  18. data/gemfiles/Gemfile-rails-7 +9 -0
  19. data/index.js +2 -2
  20. data/lib/ar_sync/class_methods.rb +71 -36
  21. data/lib/ar_sync/collection.rb +23 -19
  22. data/lib/ar_sync/core.rb +3 -3
  23. data/lib/ar_sync/instance_methods.rb +7 -4
  24. data/lib/ar_sync/rails.rb +1 -1
  25. data/lib/ar_sync/type_script.rb +50 -14
  26. data/lib/ar_sync/version.rb +1 -1
  27. data/lib/generators/ar_sync/install/install_generator.rb +1 -1
  28. data/package-lock.json +1706 -227
  29. data/package.json +1 -1
  30. data/src/core/{ActioncableAdapter.ts → ActionCableAdapter.ts} +0 -0
  31. data/src/core/ArSyncApi.ts +20 -7
  32. data/src/core/ArSyncStore.ts +177 -125
  33. data/src/core/ConnectionManager.ts +1 -0
  34. data/src/core/DataType.ts +15 -16
  35. data/src/core/hooks.ts +31 -7
  36. data/tsconfig.json +2 -2
  37. data/vendor/assets/javascripts/{ar_sync_actioncable_adapter.js.erb → ar_sync_action_cable_adapter.js.erb} +1 -1
  38. metadata +17 -16
  39. data/core/ActioncableAdapter.js +0 -29
  40. data/lib/ar_sync/field.rb +0 -96
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 949fc166a975785ab522fe3a2714bf334a56c1f2d4e32931aced7b3ee1de65ac
4
- data.tar.gz: f9428cc4dbf7e2e7cea7c2f958198e628f7ad92241d71c351e8328b856a315de
3
+ metadata.gz: ab145d5094c25600e95e01ab625c0128782b2a0592be95d8c9333539a5128bd1
4
+ data.tar.gz: 062fcf8cb8996e145dfa35eb25b31f2ecc2b4a486183bc70678d055db2bf2bc8
5
5
  SHA512:
6
- metadata.gz: dff083ce7735e475c3104b7581da185e8bd872e76afd8addeecfd5ebc9d292cb299358edeb9d445c5aac268813d4bd358a886bd89dff761eab8dbbac2fa75593
7
- data.tar.gz: 54ce2594a8749284200924456188fc7b7a3836f8719cbaea4b2626823e9bbe1879cc6a8d7dad327e82f83d7f48d488620eef18f94bda6297aecf1c87d3893b85
6
+ metadata.gz: 556a1c954088cea90d44bb61cec1fc250804f1fc5ec4e1c4101ff642343af49bc4ce8870be152de4627802931409d3c5f25707fa34b59ba8e53e9873a99e9b54
7
+ data.tar.gz: 28846608f3314be4a117d1ffbf265702f2170755f027696300f991b01a9228302d7e218fce757826c7528c8643d98f66e1073741305c1d851f1fe6602c9f185b
@@ -0,0 +1,27 @@
1
+ name: Test
2
+ on: [push, pull_request]
3
+ jobs:
4
+ test:
5
+ strategy:
6
+ fail-fast: false
7
+ matrix:
8
+ ruby: [ '2.7', '3.0', '3.1' ]
9
+ gemfiles:
10
+ - gemfiles/Gemfile-rails-6
11
+ - gemfiles/Gemfile-rails-7
12
+ runs-on: ubuntu-latest
13
+ steps:
14
+ - uses: actions/checkout@v2
15
+ - uses: ruby/setup-ruby@v1
16
+ with:
17
+ ruby-version: ${{ matrix.ruby }}
18
+ - uses: actions/setup-node@v1
19
+ with:
20
+ node-version: '14.x'
21
+ - run: |
22
+ sudo apt-get update
23
+ sudo apt-get install -y libsqlite3-dev
24
+ - run: bundle install --gemfile ${{ matrix.gemfiles }} --jobs 4 --retry 3
25
+ - run: npm install
26
+ - run: npm run build
27
+ - run: bundle exec --gemfile ${{ matrix.gemfiles }} rake
data/Gemfile CHANGED
@@ -4,3 +4,4 @@ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
4
 
5
5
  # Specify your gem's dependencies in ar_sync.gemspec
6
6
  gemspec
7
+ gem 'ar_serializer'
data/Gemfile.lock CHANGED
@@ -1,56 +1,54 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ar_sync (1.0.3)
4
+ ar_sync (1.1.0)
5
5
  activerecord
6
- ar_serializer (= 1.0.0)
6
+ ar_serializer
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- activemodel (5.2.3)
12
- activesupport (= 5.2.3)
13
- activerecord (5.2.3)
14
- activemodel (= 5.2.3)
15
- activesupport (= 5.2.3)
16
- arel (>= 9.0)
17
- activerecord-import (1.0.2)
18
- activerecord (>= 3.2)
19
- activesupport (5.2.3)
11
+ activemodel (7.0.2.3)
12
+ activesupport (= 7.0.2.3)
13
+ activerecord (7.0.2.3)
14
+ activemodel (= 7.0.2.3)
15
+ activesupport (= 7.0.2.3)
16
+ activerecord-import (1.4.0)
17
+ activerecord (>= 4.2)
18
+ activesupport (7.0.2.3)
20
19
  concurrent-ruby (~> 1.0, >= 1.0.2)
21
- i18n (>= 0.7, < 2)
22
- minitest (~> 5.1)
23
- tzinfo (~> 1.1)
24
- ar_serializer (1.0.0)
20
+ i18n (>= 1.6, < 2)
21
+ minitest (>= 5.1)
22
+ tzinfo (~> 2.0)
23
+ ar_serializer (1.2.0)
25
24
  activerecord
26
25
  top_n_loader
27
- arel (9.0.0)
28
- coderay (1.1.2)
29
- concurrent-ruby (1.1.5)
30
- i18n (1.6.0)
26
+ coderay (1.1.3)
27
+ concurrent-ruby (1.1.10)
28
+ i18n (1.10.0)
31
29
  concurrent-ruby (~> 1.0)
32
- method_source (0.9.2)
33
- minitest (5.11.3)
34
- pry (0.12.2)
35
- coderay (~> 1.1.0)
36
- method_source (~> 0.9.0)
37
- rake (12.3.2)
38
- sqlite3 (1.3.13)
39
- thread_safe (0.3.6)
40
- top_n_loader (1.0.0)
30
+ method_source (1.0.0)
31
+ minitest (5.15.0)
32
+ pry (0.14.1)
33
+ coderay (~> 1.1)
34
+ method_source (~> 1.0)
35
+ rake (13.0.6)
36
+ sqlite3 (1.4.2)
37
+ top_n_loader (1.0.2)
41
38
  activerecord
42
- tzinfo (1.2.5)
43
- thread_safe (~> 0.1)
39
+ tzinfo (2.0.4)
40
+ concurrent-ruby (~> 1.0)
44
41
 
45
42
  PLATFORMS
46
43
  ruby
47
44
 
48
45
  DEPENDENCIES
49
46
  activerecord-import
47
+ ar_serializer
50
48
  ar_sync!
51
49
  pry
52
50
  rake
53
51
  sqlite3
54
52
 
55
53
  BUNDLED WITH
56
- 1.16.1
54
+ 2.1.2
data/ar_sync.gemspec CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.require_paths = ['lib']
22
22
 
23
23
  spec.add_dependency 'activerecord'
24
- spec.add_dependency 'ar_serializer', '1.0.0'
24
+ spec.add_dependency 'ar_serializer'
25
25
  %w[rake pry sqlite3 activerecord-import].each do |gem_name|
26
26
  spec.add_development_dependency gem_name
27
27
  end
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var ActionCableAdapter = /** @class */ (function () {
4
+ function ActionCableAdapter(actionCableClass) {
5
+ this.connected = true;
6
+ this.actionCableClass = actionCableClass;
7
+ this.subscribe(Math.random().toString(), function () { });
8
+ }
9
+ ActionCableAdapter.prototype.subscribe = function (key, received) {
10
+ var _this = this;
11
+ var disconnected = function () {
12
+ if (!_this.connected)
13
+ return;
14
+ _this.connected = false;
15
+ _this.ondisconnect();
16
+ };
17
+ var connected = function () {
18
+ if (_this.connected)
19
+ return;
20
+ _this.connected = true;
21
+ _this.onreconnect();
22
+ };
23
+ if (!this._cable)
24
+ this._cable = this.actionCableClass.createConsumer();
25
+ return this._cable.subscriptions.create({ channel: 'SyncChannel', key: key }, { received: received, disconnected: disconnected, connected: connected });
26
+ };
27
+ ActionCableAdapter.prototype.ondisconnect = function () { };
28
+ ActionCableAdapter.prototype.onreconnect = function () { };
29
+ return ActionCableAdapter;
30
+ }());
31
+ exports.default = ActionCableAdapter;
data/core/ArSyncApi.d.ts CHANGED
@@ -1,8 +1,14 @@
1
1
  declare function apiBatchFetch(endpoint: string, requests: object[]): Promise<any>;
2
+ declare type Request = {
3
+ api: string;
4
+ params?: any;
5
+ query: any;
6
+ id?: number;
7
+ };
2
8
  declare const ArSyncApi: {
3
9
  domain: string | null;
4
10
  _batchFetch: typeof apiBatchFetch;
5
- fetch: (request: object) => Promise<unknown>;
6
- syncFetch: (request: object) => Promise<unknown>;
11
+ fetch: (request: Request) => Promise<unknown>;
12
+ syncFetch: (request: Request) => Promise<unknown>;
7
13
  };
8
14
  export default ArSyncApi;
data/core/ArSyncApi.js CHANGED
@@ -1,79 +1,153 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- async function apiBatchFetch(endpoint, requests) {
4
- const headers = {
5
- 'Accept': 'application/json',
6
- 'Content-Type': 'application/json'
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
7
10
  };
8
- const body = JSON.stringify({ requests });
9
- const option = { credentials: 'include', method: 'POST', headers, body };
10
- if (ArSyncApi.domain)
11
- endpoint = ArSyncApi.domain + endpoint;
12
- const res = await fetch(endpoint, option);
13
- if (res.status === 200)
14
- return res.json();
15
- throw new Error(res.statusText);
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (_) try {
29
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
49
+ Object.defineProperty(exports, "__esModule", { value: true });
50
+ function apiBatchFetch(endpoint, requests) {
51
+ return __awaiter(this, void 0, void 0, function () {
52
+ var headers, body, option, res;
53
+ return __generator(this, function (_a) {
54
+ switch (_a.label) {
55
+ case 0:
56
+ headers = {
57
+ 'Accept': 'application/json',
58
+ 'Content-Type': 'application/json'
59
+ };
60
+ body = JSON.stringify({ requests: requests });
61
+ option = { credentials: 'include', method: 'POST', headers: headers, body: body };
62
+ if (ArSyncApi.domain)
63
+ endpoint = ArSyncApi.domain + endpoint;
64
+ return [4 /*yield*/, fetch(endpoint, option)];
65
+ case 1:
66
+ res = _a.sent();
67
+ if (res.status === 200)
68
+ return [2 /*return*/, res.json()];
69
+ throw new Error(res.statusText);
70
+ }
71
+ });
72
+ });
16
73
  }
17
- class ApiFetcher {
18
- constructor(endpoint) {
74
+ var ApiFetcher = /** @class */ (function () {
75
+ function ApiFetcher(endpoint) {
19
76
  this.batches = [];
20
77
  this.batchFetchTimer = null;
21
78
  this.endpoint = endpoint;
22
79
  }
23
- fetch(request) {
24
- return new Promise((resolve, reject) => {
25
- this.batches.push([request, { resolve, reject }]);
26
- if (this.batchFetchTimer)
80
+ ApiFetcher.prototype.fetch = function (request) {
81
+ var _this = this;
82
+ if (request.id != null) {
83
+ return new Promise(function (resolve, reject) {
84
+ _this.fetch({ api: request.api, params: { ids: [request.id] }, query: request.query }).then(function (result) {
85
+ if (result[0])
86
+ resolve(result[0]);
87
+ else
88
+ reject({ type: 'Not Found', retry: false });
89
+ }).catch(reject);
90
+ });
91
+ }
92
+ return new Promise(function (resolve, reject) {
93
+ _this.batches.push([request, { resolve: resolve, reject: reject }]);
94
+ if (_this.batchFetchTimer)
27
95
  return;
28
- this.batchFetchTimer = setTimeout(() => {
29
- this.batchFetchTimer = null;
30
- const compacts = {};
31
- const requests = [];
32
- const callbacksList = [];
33
- for (const batch of this.batches) {
34
- const request = batch[0];
35
- const callback = batch[1];
36
- const key = JSON.stringify(request);
96
+ _this.batchFetchTimer = setTimeout(function () {
97
+ _this.batchFetchTimer = null;
98
+ var compacts = {};
99
+ var requests = [];
100
+ var callbacksList = [];
101
+ for (var _i = 0, _a = _this.batches; _i < _a.length; _i++) {
102
+ var batch = _a[_i];
103
+ var request_1 = batch[0];
104
+ var callback = batch[1];
105
+ var key = JSON.stringify(request_1);
37
106
  if (compacts[key]) {
38
107
  compacts[key].push(callback);
39
108
  }
40
109
  else {
41
- requests.push(request);
110
+ requests.push(request_1);
42
111
  callbacksList.push(compacts[key] = [callback]);
43
112
  }
44
113
  }
45
- this.batches = [];
46
- ArSyncApi._batchFetch(this.endpoint, requests).then((results) => {
47
- for (const i in callbacksList) {
48
- const result = results[i];
49
- const callbacks = callbacksList[i];
50
- for (const callback of callbacks) {
51
- if (result.data) {
114
+ _this.batches = [];
115
+ ArSyncApi._batchFetch(_this.endpoint, requests).then(function (results) {
116
+ for (var i in callbacksList) {
117
+ var result = results[i];
118
+ var callbacks = callbacksList[i];
119
+ for (var _i = 0, callbacks_1 = callbacks; _i < callbacks_1.length; _i++) {
120
+ var callback = callbacks_1[_i];
121
+ if (result.data !== undefined) {
52
122
  callback.resolve(result.data);
53
123
  }
54
124
  else {
55
- const error = result.error || { type: 'Unknown Error' };
56
- callback.reject(Object.assign(Object.assign({}, error), { retry: false }));
125
+ var error = result.error || { type: 'Unknown Error' };
126
+ callback.reject(__assign(__assign({}, error), { retry: false }));
57
127
  }
58
128
  }
59
129
  }
60
- }).catch(e => {
61
- const error = { type: e.name, message: e.message, retry: true };
62
- for (const callbacks of callbacksList) {
63
- for (const callback of callbacks)
130
+ }).catch(function (e) {
131
+ var error = { type: e.name, message: e.message, retry: true };
132
+ for (var _i = 0, callbacksList_1 = callbacksList; _i < callbacksList_1.length; _i++) {
133
+ var callbacks = callbacksList_1[_i];
134
+ for (var _a = 0, callbacks_2 = callbacks; _a < callbacks_2.length; _a++) {
135
+ var callback = callbacks_2[_a];
64
136
  callback.reject(error);
137
+ }
65
138
  }
66
139
  });
67
140
  }, 16);
68
141
  });
69
- }
70
- }
71
- const staticFetcher = new ApiFetcher('/static_api');
72
- const syncFetcher = new ApiFetcher('/sync_api');
73
- const ArSyncApi = {
142
+ };
143
+ return ApiFetcher;
144
+ }());
145
+ var staticFetcher = new ApiFetcher('/static_api');
146
+ var syncFetcher = new ApiFetcher('/sync_api');
147
+ var ArSyncApi = {
74
148
  domain: null,
75
149
  _batchFetch: apiBatchFetch,
76
- fetch: (request) => staticFetcher.fetch(request),
77
- syncFetch: (request) => syncFetcher.fetch(request),
150
+ fetch: function (request) { return staticFetcher.fetch(request); },
151
+ syncFetch: function (request) { return syncFetcher.fetch(request); },
78
152
  };
79
153
  exports.default = ArSyncApi;
data/core/ArSyncModel.js CHANGED
@@ -1,104 +1,107 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const ArSyncStore_1 = require("./ArSyncStore");
4
- const ConnectionManager_1 = require("./ConnectionManager");
5
- class ArSyncModel {
6
- constructor(request, option) {
3
+ var ArSyncStore_1 = require("./ArSyncStore");
4
+ var ConnectionManager_1 = require("./ConnectionManager");
5
+ var ArSyncModel = /** @class */ (function () {
6
+ function ArSyncModel(request, option) {
7
+ var _this = this;
7
8
  this._ref = ArSyncModel.retrieveRef(request, option);
8
9
  this._listenerSerial = 0;
9
10
  this._listeners = {};
10
11
  this.complete = false;
11
12
  this.connected = ArSyncStore_1.default.connectionManager.networkStatus;
12
- const setData = () => {
13
- this.data = this._ref.model.data;
14
- this.complete = this._ref.model.complete;
15
- this.notfound = this._ref.model.notfound;
13
+ var setData = function () {
14
+ _this.data = _this._ref.model.data;
15
+ _this.complete = _this._ref.model.complete;
16
+ _this.notfound = _this._ref.model.notfound;
16
17
  };
17
18
  setData();
18
19
  this.subscribe('load', setData);
19
20
  this.subscribe('change', setData);
20
- this.subscribe('connection', (status) => {
21
- this.connected = status;
21
+ this.subscribe('connection', function (status) {
22
+ _this.connected = status;
22
23
  });
23
24
  }
24
- onload(callback) {
25
+ ArSyncModel.prototype.onload = function (callback) {
25
26
  this.subscribeOnce('load', callback);
26
- }
27
- subscribeOnce(event, callback) {
28
- const subscription = this.subscribe(event, (arg) => {
27
+ };
28
+ ArSyncModel.prototype.subscribeOnce = function (event, callback) {
29
+ var subscription = this.subscribe(event, function (arg) {
29
30
  callback(arg);
30
31
  subscription.unsubscribe();
31
32
  });
32
33
  return subscription;
33
- }
34
- dig(path) {
34
+ };
35
+ ArSyncModel.prototype.dig = function (path) {
35
36
  return ArSyncModel.digData(this.data, path);
36
- }
37
- static digData(data, path) {
37
+ };
38
+ ArSyncModel.digData = function (data, path) {
38
39
  function dig(data, path) {
39
40
  if (path.length === 0)
40
41
  return data;
41
42
  if (data == null)
42
43
  return data;
43
- const key = path[0];
44
- const other = path.slice(1);
44
+ var key = path[0];
45
+ var other = path.slice(1);
45
46
  if (Array.isArray(data)) {
46
- return this.digData(data.find(el => el.id === key), other);
47
+ return this.digData(data.find(function (el) { return el.id === key; }), other);
47
48
  }
48
49
  else {
49
50
  return this.digData(data[key], other);
50
51
  }
51
52
  }
52
53
  return dig(data, path);
53
- }
54
- subscribe(event, callback) {
55
- const id = this._listenerSerial++;
56
- const subscription = this._ref.model.subscribe(event, callback);
57
- let unsubscribed = false;
58
- const unsubscribe = () => {
54
+ };
55
+ ArSyncModel.prototype.subscribe = function (event, callback) {
56
+ var _this = this;
57
+ var id = this._listenerSerial++;
58
+ var subscription = this._ref.model.subscribe(event, callback);
59
+ var unsubscribed = false;
60
+ var unsubscribe = function () {
59
61
  unsubscribed = true;
60
62
  subscription.unsubscribe();
61
- delete this._listeners[id];
63
+ delete _this._listeners[id];
62
64
  };
63
65
  if (this.complete) {
64
66
  if (event === 'load')
65
- setTimeout(() => {
67
+ setTimeout(function () {
66
68
  if (!unsubscribed)
67
69
  callback();
68
70
  }, 0);
69
71
  if (event === 'change')
70
- setTimeout(() => {
72
+ setTimeout(function () {
71
73
  if (!unsubscribed)
72
- callback({ path: [], value: this.data });
74
+ callback({ path: [], value: _this.data });
73
75
  }, 0);
74
76
  }
75
- return this._listeners[id] = { unsubscribe };
76
- }
77
- release() {
78
- for (const id in this._listeners)
77
+ return this._listeners[id] = { unsubscribe: unsubscribe };
78
+ };
79
+ ArSyncModel.prototype.release = function () {
80
+ for (var id in this._listeners)
79
81
  this._listeners[id].unsubscribe();
80
82
  this._listeners = {};
81
83
  ArSyncModel._detach(this._ref);
82
84
  this._ref = null;
83
- }
84
- static retrieveRef(request, option) {
85
- const key = JSON.stringify([request, option]);
86
- let ref = this._cache[key];
85
+ };
86
+ ArSyncModel.retrieveRef = function (request, option) {
87
+ var key = JSON.stringify([request, option]);
88
+ var ref = this._cache[key];
87
89
  if (!ref) {
88
- const model = new ArSyncStore_1.default(request, option);
89
- ref = this._cache[key] = { key, count: 0, timer: null, model };
90
+ var model = new ArSyncStore_1.default(request, option);
91
+ ref = this._cache[key] = { key: key, count: 0, timer: null, model: model };
90
92
  }
91
93
  this._attach(ref);
92
94
  return ref;
93
- }
94
- static _detach(ref) {
95
+ };
96
+ ArSyncModel._detach = function (ref) {
97
+ var _this = this;
95
98
  ref.count--;
96
- const timeout = this.cacheTimeout;
99
+ var timeout = this.cacheTimeout;
97
100
  if (ref.count !== 0)
98
101
  return;
99
- const timedout = () => {
102
+ var timedout = function () {
100
103
  ref.model.release();
101
- delete this._cache[ref.key];
104
+ delete _this._cache[ref.key];
102
105
  };
103
106
  if (timeout) {
104
107
  ref.timer = setTimeout(timedout, timeout);
@@ -106,28 +109,34 @@ class ArSyncModel {
106
109
  else {
107
110
  timedout();
108
111
  }
109
- }
110
- static _attach(ref) {
112
+ };
113
+ ArSyncModel._attach = function (ref) {
111
114
  ref.count++;
112
115
  if (ref.timer)
113
116
  clearTimeout(ref.timer);
114
- }
115
- static setConnectionAdapter(adapter) {
117
+ };
118
+ ArSyncModel.setConnectionAdapter = function (adapter) {
116
119
  ArSyncStore_1.default.connectionManager = new ConnectionManager_1.default(adapter);
117
- }
118
- static waitForLoad(...models) {
119
- return new Promise((resolve) => {
120
- let count = 0;
121
- for (const model of models) {
122
- model.onload(() => {
120
+ };
121
+ ArSyncModel.waitForLoad = function () {
122
+ var models = [];
123
+ for (var _i = 0; _i < arguments.length; _i++) {
124
+ models[_i] = arguments[_i];
125
+ }
126
+ return new Promise(function (resolve) {
127
+ var count = 0;
128
+ for (var _i = 0, models_1 = models; _i < models_1.length; _i++) {
129
+ var model = models_1[_i];
130
+ model.onload(function () {
123
131
  count++;
124
132
  if (models.length == count)
125
133
  resolve(models);
126
134
  });
127
135
  }
128
136
  });
129
- }
130
- }
137
+ };
138
+ ArSyncModel._cache = {};
139
+ ArSyncModel.cacheTimeout = 10 * 1000;
140
+ return ArSyncModel;
141
+ }());
131
142
  exports.default = ArSyncModel;
132
- ArSyncModel._cache = {};
133
- ArSyncModel.cacheTimeout = 10 * 1000;