ar_sync 1.1.0 → 1.1.2

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
  SHA256:
3
- metadata.gz: ab145d5094c25600e95e01ab625c0128782b2a0592be95d8c9333539a5128bd1
4
- data.tar.gz: 062fcf8cb8996e145dfa35eb25b31f2ecc2b4a486183bc70678d055db2bf2bc8
3
+ metadata.gz: '096573e72fb5d4dc465e79c9bf8b39617fb423d7d779534f4ce30768dda2b5b1'
4
+ data.tar.gz: c590f23a76420db7e056733ca895e56991cdcca8cfbd9908a503dc5ce57ab2f7
5
5
  SHA512:
6
- metadata.gz: 556a1c954088cea90d44bb61cec1fc250804f1fc5ec4e1c4101ff642343af49bc4ce8870be152de4627802931409d3c5f25707fa34b59ba8e53e9873a99e9b54
7
- data.tar.gz: 28846608f3314be4a117d1ffbf265702f2170755f027696300f991b01a9228302d7e218fce757826c7528c8643d98f66e1073741305c1d851f1fe6602c9f185b
6
+ metadata.gz: 47d42249688cfef025fd2b9ea927d81962a786eded059a694ac5d069e7a0b0a48ca9bcc0d59a8d198bc4bb701cd86d4b98acc5c2c3de5b3018ac78f4b9487566
7
+ data.tar.gz: 88e61169ef8968905d8e9f341108f2c926ac23436ce30ad5e8f2ca7872a6e4e2644f24ff44769c5561589ba1954367325001675c2014b838053ccb6b1848ace9
@@ -5,13 +5,14 @@ jobs:
5
5
  strategy:
6
6
  fail-fast: false
7
7
  matrix:
8
- ruby: [ '2.7', '3.0', '3.1' ]
8
+ ruby: [ '3.1', '3.2', '3.3' ]
9
9
  gemfiles:
10
10
  - gemfiles/Gemfile-rails-6
11
- - gemfiles/Gemfile-rails-7
11
+ - gemfiles/Gemfile-rails-7-0
12
+ - gemfiles/Gemfile-rails-7-1
12
13
  runs-on: ubuntu-latest
13
14
  steps:
14
- - uses: actions/checkout@v2
15
+ - uses: actions/checkout@v4
15
16
  - uses: ruby/setup-ruby@v1
16
17
  with:
17
18
  ruby-version: ${{ matrix.ruby }}
data/.gitignore CHANGED
@@ -7,7 +7,9 @@
7
7
  /spec/reports/
8
8
  /tmp/
9
9
  /test/*.sqlite3
10
+ /test/*.sqlite3-*
10
11
  /test/generated_*
11
12
  .ruby-version
12
13
  /node_modules/
13
14
  tsconfig.tsbuildinfo
15
+ Gemfile.lock
data/Gemfile CHANGED
@@ -4,4 +4,5 @@ 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 'sqlite3', '~> 1.4'
7
8
  gem 'ar_serializer'
data/ar_sync.gemspec CHANGED
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
22
22
 
23
23
  spec.add_dependency 'activerecord'
24
24
  spec.add_dependency 'ar_serializer'
25
- %w[rake pry sqlite3 activerecord-import].each do |gem_name|
25
+ %w[rake sqlite3 activerecord-import].each do |gem_name|
26
26
  spec.add_development_dependency gem_name
27
27
  end
28
28
  end
data/bin/console CHANGED
@@ -2,10 +2,10 @@
2
2
 
3
3
  require 'bundler/setup'
4
4
  require 'ar_sync'
5
- require 'pry'
5
+ require 'irb'
6
6
  require_relative '../test/model'
7
7
  ArSync.on_notification do |events|
8
8
  puts "\e[1m#{events.inspect}\e[m"
9
9
  end
10
10
 
11
- Pry.start
11
+ IRB.start
@@ -1,9 +1,5 @@
1
+ import { ArSyncStore, Request } from './ArSyncStore';
1
2
  import ConnectionAdapter from './ConnectionAdapter';
2
- interface Request {
3
- api: string;
4
- query: any;
5
- params?: any;
6
- }
7
3
  declare type Path = Readonly<(string | number)[]>;
8
4
  interface Change {
9
5
  path: Path;
@@ -12,8 +8,14 @@ interface Change {
12
8
  declare type ChangeCallback = (change: Change) => void;
13
9
  declare type LoadCallback = () => void;
14
10
  declare type ConnectionCallback = (status: boolean) => void;
15
- declare type SubscriptionType = 'load' | 'change' | 'connection';
11
+ declare type SubscriptionType = 'load' | 'change' | 'connection' | 'destroy';
16
12
  declare type SubscriptionCallback = ChangeCallback | LoadCallback | ConnectionCallback;
13
+ declare type ArSyncModelRef = {
14
+ key: string;
15
+ count: number;
16
+ timer: number | null;
17
+ model: ArSyncStore;
18
+ };
17
19
  declare type PathFirst<P extends Readonly<any[]>> = ((...args: P) => void) extends (first: infer First, ...other: any) => void ? First : never;
18
20
  declare type PathRest<U> = U extends Readonly<any[]> ? ((...args: U) => any) extends (head: any, ...args: infer T) => any ? U extends Readonly<[any, any, ...any[]]> ? T : never : never : never;
19
21
  declare type DigResult<Data, P extends Readonly<any[]>> = Data extends null | undefined ? Data : PathFirst<P> extends never ? Data : PathFirst<P> extends keyof Data ? (Data extends Readonly<any[]> ? undefined : never) | {
@@ -26,6 +28,7 @@ export default class ArSyncModel<T> {
26
28
  private _listeners;
27
29
  complete: boolean;
28
30
  notfound?: boolean;
31
+ destroyed: boolean;
29
32
  connected: boolean;
30
33
  data: T | null;
31
34
  static _cache: {
@@ -52,12 +55,7 @@ export default class ArSyncModel<T> {
52
55
  release(): void;
53
56
  static retrieveRef(request: Request, option?: {
54
57
  immutable: boolean;
55
- }): {
56
- key: string;
57
- count: number;
58
- timer: number | null;
59
- model: any;
60
- };
58
+ }): ArSyncModelRef;
61
59
  static _detach(ref: any): void;
62
60
  private static _attach;
63
61
  static setConnectionAdapter(adapter: ConnectionAdapter): void;
data/core/ArSyncModel.js CHANGED
@@ -5,19 +5,22 @@ var ConnectionManager_1 = require("./ConnectionManager");
5
5
  var ArSyncModel = /** @class */ (function () {
6
6
  function ArSyncModel(request, option) {
7
7
  var _this = this;
8
+ this.complete = false;
9
+ this.destroyed = false;
8
10
  this._ref = ArSyncModel.retrieveRef(request, option);
9
11
  this._listenerSerial = 0;
10
12
  this._listeners = {};
11
- this.complete = false;
12
- this.connected = ArSyncStore_1.default.connectionManager.networkStatus;
13
+ this.connected = ArSyncStore_1.ArSyncStore.connectionManager.networkStatus;
13
14
  var setData = function () {
14
15
  _this.data = _this._ref.model.data;
15
16
  _this.complete = _this._ref.model.complete;
16
17
  _this.notfound = _this._ref.model.notfound;
18
+ _this.destroyed = _this._ref.model.destroyed;
17
19
  };
18
20
  setData();
19
21
  this.subscribe('load', setData);
20
22
  this.subscribe('change', setData);
23
+ this.subscribe('destroy', setData);
21
24
  this.subscribe('connection', function (status) {
22
25
  _this.connected = status;
23
26
  });
@@ -81,13 +84,12 @@ var ArSyncModel = /** @class */ (function () {
81
84
  this._listeners[id].unsubscribe();
82
85
  this._listeners = {};
83
86
  ArSyncModel._detach(this._ref);
84
- this._ref = null;
85
87
  };
86
88
  ArSyncModel.retrieveRef = function (request, option) {
87
89
  var key = JSON.stringify([request, option]);
88
90
  var ref = this._cache[key];
89
91
  if (!ref) {
90
- var model = new ArSyncStore_1.default(request, option);
92
+ var model = new ArSyncStore_1.ArSyncStore(request, option);
91
93
  ref = this._cache[key] = { key: key, count: 0, timer: null, model: model };
92
94
  }
93
95
  this._attach(ref);
@@ -116,7 +118,7 @@ var ArSyncModel = /** @class */ (function () {
116
118
  clearTimeout(ref.timer);
117
119
  };
118
120
  ArSyncModel.setConnectionAdapter = function (adapter) {
119
- ArSyncStore_1.default.connectionManager = new ConnectionManager_1.default(adapter);
121
+ ArSyncStore_1.ArSyncStore.connectionManager = new ConnectionManager_1.default(adapter);
120
122
  };
121
123
  ArSyncModel.waitForLoad = function () {
122
124
  var models = [];
@@ -1,20 +1,28 @@
1
- export default class ArSyncStore {
1
+ export declare type Request = {
2
+ api: string;
3
+ query: any;
4
+ params?: any;
5
+ id?: any;
6
+ };
7
+ export declare class ArSyncStore {
2
8
  immutable: boolean;
3
9
  markedForFreezeObjects: any[];
4
10
  changes: any;
5
11
  eventListeners: any;
6
12
  markForRelease: true | undefined;
7
13
  container: any;
8
- request: any;
14
+ request: Request;
9
15
  complete: boolean;
10
16
  notfound?: boolean;
17
+ destroyed: boolean;
11
18
  data: any;
12
19
  changesBufferTimer: number | undefined | null;
13
20
  retryLoadTimer: number | undefined | null;
14
21
  static connectionManager: any;
15
- constructor(request: any, { immutable }?: {
22
+ constructor(request: Request, { immutable }?: {
16
23
  immutable?: boolean | undefined;
17
24
  });
25
+ handleDestroy(): void;
18
26
  load(retryCount: number): void;
19
27
  setChangesBufferTimer(): void;
20
28
  subscribe(event: any, callback: any): {