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 +4 -4
- data/.github/workflows/test.yml +4 -3
- data/.gitignore +2 -0
- data/Gemfile +1 -0
- data/ar_sync.gemspec +1 -1
- data/bin/console +2 -2
- data/core/ArSyncModel.d.ts +10 -12
- data/core/ArSyncModel.js +7 -5
- data/core/ArSyncStore.d.ts +11 -3
- data/core/ArSyncStore.js +112 -112
- data/core/hooks.d.ts +1 -0
- data/core/hooks.js +5 -4
- data/gemfiles/Gemfile-rails-6 +4 -3
- data/gemfiles/{Gemfile-rails-7 → Gemfile-rails-7-0} +4 -3
- data/gemfiles/Gemfile-rails-7-1 +10 -0
- data/lib/ar_sync/class_methods.rb +1 -5
- data/lib/ar_sync/core.rb +2 -6
- data/lib/ar_sync/instance_methods.rb +16 -1
- data/lib/ar_sync/rails.rb +14 -17
- data/lib/ar_sync/version.rb +1 -1
- data/src/core/ArSyncModel.ts +9 -8
- data/src/core/ArSyncStore.ts +128 -121
- data/src/core/hooks.ts +6 -5
- metadata +5 -19
- data/Gemfile.lock +0 -54
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '096573e72fb5d4dc465e79c9bf8b39617fb423d7d779534f4ce30768dda2b5b1'
|
4
|
+
data.tar.gz: c590f23a76420db7e056733ca895e56991cdcca8cfbd9908a503dc5ce57ab2f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 47d42249688cfef025fd2b9ea927d81962a786eded059a694ac5d069e7a0b0a48ca9bcc0d59a8d198bc4bb701cd86d4b98acc5c2c3de5b3018ac78f4b9487566
|
7
|
+
data.tar.gz: 88e61169ef8968905d8e9f341108f2c926ac23436ce30ad5e8f2ca7872a6e4e2644f24ff44769c5561589ba1954367325001675c2014b838053ccb6b1848ace9
|
data/.github/workflows/test.yml
CHANGED
@@ -5,13 +5,14 @@ jobs:
|
|
5
5
|
strategy:
|
6
6
|
fail-fast: false
|
7
7
|
matrix:
|
8
|
-
ruby: [ '
|
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@
|
15
|
+
- uses: actions/checkout@v4
|
15
16
|
- uses: ruby/setup-ruby@v1
|
16
17
|
with:
|
17
18
|
ruby-version: ${{ matrix.ruby }}
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
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
|
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
data/core/ArSyncModel.d.ts
CHANGED
@@ -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.
|
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.
|
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.
|
121
|
+
ArSyncStore_1.ArSyncStore.connectionManager = new ConnectionManager_1.default(adapter);
|
120
122
|
};
|
121
123
|
ArSyncModel.waitForLoad = function () {
|
122
124
|
var models = [];
|
data/core/ArSyncStore.d.ts
CHANGED
@@ -1,20 +1,28 @@
|
|
1
|
-
export
|
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:
|
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:
|
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): {
|