jpf-mobx 1.0.157 → 1.0.159
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.
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -15
- package/dist/index.js.map +1 -1
- package/dist/observable.d.ts +19 -13
- package/dist/observable.js +57 -51
- package/dist/observable.js.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +5 -18
- package/src/observable.ts +89 -74
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { controls, utilities, attributes, element, event,
|
|
1
|
+
import { controls, utilities, attributes, element, event, properties, root, style, css } from "jpf";
|
|
2
|
+
import * as observable from "./observable";
|
|
2
3
|
export { controls };
|
|
3
4
|
export { utilities };
|
|
4
5
|
export { attributes };
|
|
5
6
|
export { element };
|
|
6
7
|
export { event };
|
|
7
|
-
export { observableInterfaces };
|
|
8
8
|
export { properties };
|
|
9
9
|
export { root };
|
|
10
10
|
export { style };
|
|
11
11
|
export { css };
|
|
12
|
-
export
|
|
12
|
+
export { observable };
|
package/dist/index.js
CHANGED
|
@@ -1,25 +1,13 @@
|
|
|
1
|
-
import { controls, utilities, attributes, element, event,
|
|
2
|
-
import
|
|
3
|
-
observableImplementations.implementations.unwrap = unwrap;
|
|
4
|
-
observableImplementations.implementations.isComputed = isComputed;
|
|
5
|
-
observableImplementations.implementations.isObservableValue = isObservableValue;
|
|
6
|
-
observableImplementations.implementations.isObservableArray = isObservableArray;
|
|
7
|
-
observableImplementations.implementations.isObservableMap = isObservableMap;
|
|
8
|
-
observableImplementations.implementations.isObservableSet = isObservableSet;
|
|
9
|
-
observableImplementations.implementations.computed = computed;
|
|
10
|
-
observableImplementations.implementations.observableValue = observableValue;
|
|
11
|
-
observableImplementations.implementations.observableArray = observableArray;
|
|
12
|
-
observableImplementations.implementations.observableMap = observableMap;
|
|
13
|
-
observableImplementations.implementations.observableSet = observableSet;
|
|
1
|
+
import { controls, utilities, attributes, element, event, properties, root, style, css } from "jpf";
|
|
2
|
+
import * as observable from "./observable";
|
|
14
3
|
export { controls };
|
|
15
4
|
export { utilities };
|
|
16
5
|
export { attributes };
|
|
17
6
|
export { element };
|
|
18
7
|
export { event };
|
|
19
|
-
export { observableInterfaces };
|
|
20
8
|
export { properties };
|
|
21
9
|
export { root };
|
|
22
10
|
export { style };
|
|
23
11
|
export { css };
|
|
24
|
-
export
|
|
12
|
+
export { observable };
|
|
25
13
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,QAAQ,EACR,SAAS,EACT,UAAU,EACV,OAAO,EACP,KAAK,EACL,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,QAAQ,EACR,SAAS,EACT,UAAU,EACV,OAAO,EACP,KAAK,EACL,UAAU,EACV,IAAI,EACJ,KAAK,EACL,GAAG,EACN,MAAM,KAAK,CAAC;AAEb,OAAO,KAAK,UAAU,MAAM,cAAc,CAAC;AAG3C,OAAO,EAAE,QAAQ,EAAE,CAAC;AACpB,OAAO,EAAE,SAAS,EAAE,CAAC;AACrB,OAAO,EAAE,UAAU,EAAE,CAAC;AACtB,OAAO,EAAE,OAAO,EAAE,CAAC;AACnB,OAAO,EAAE,KAAK,EAAE,CAAC;AACjB,OAAO,EAAE,UAAU,EAAE,CAAC;AACtB,OAAO,EAAE,IAAI,EAAE,CAAC;AAChB,OAAO,EAAE,KAAK,EAAE,CAAC;AACjB,OAAO,EAAE,GAAG,EAAE,CAAC;AAGf,OAAO,EAAE,UAAU,EAAE,CAAC"}
|
package/dist/observable.d.ts
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
import { IComputedValueOptions as mobxIComputedValueOptions, CreateObservableOptions as mobxCreateObservableOptions, IObservableSetInitialValues as mobxIObservableSetInitialValues, IMapEntries as mobxIMapEntries } from "mobx";
|
|
2
|
-
import {
|
|
3
|
-
export declare function computed<TComputed>(func: () => TComputed, options?: mobxIComputedValueOptions<TComputed>): observableInterfaces.IComputed<TComputed>;
|
|
2
|
+
import { observable as jpfObservable } from "jpf";
|
|
4
3
|
export declare function runInAction<T>(fn: () => T): T;
|
|
5
|
-
export
|
|
6
|
-
export
|
|
7
|
-
export
|
|
8
|
-
export
|
|
9
|
-
export
|
|
10
|
-
export
|
|
11
|
-
export
|
|
12
|
-
export declare function
|
|
13
|
-
export declare function
|
|
14
|
-
export declare function
|
|
15
|
-
export declare function
|
|
4
|
+
export type IComputed<TValue> = jpfObservable.IComputed<TValue>;
|
|
5
|
+
export type IDisposer = jpfObservable.IDisposer;
|
|
6
|
+
export type IObservableArray<TItem = any, TSetter = TItem[]> = jpfObservable.IObservableArray<TItem, TSetter>;
|
|
7
|
+
export type IObservableMap<TKey = unknown, TItem = unknown> = jpfObservable.IObservableMap<TKey, TItem>;
|
|
8
|
+
export type IObservableSet<TItem = unknown> = jpfObservable.IObservableSet<TItem>;
|
|
9
|
+
export type IObservableValue<TValue, TSetter = TValue> = jpfObservable.IObservableValue<TValue, TSetter>;
|
|
10
|
+
export type ISubscribable<TValue> = jpfObservable.ISubscribable<TValue>;
|
|
11
|
+
export declare function unwrap<TValue>(value: TValue | jpfObservable.ISubscribable<TValue>): TValue;
|
|
12
|
+
export declare function isComputed<TValue>(value: unknown): value is jpfObservable.IComputed<TValue>;
|
|
13
|
+
export declare function isObservableValue(value: any): value is jpfObservable.IObservableValue;
|
|
14
|
+
export declare function isObservableArray(value: any): value is jpfObservable.IObservableArray;
|
|
15
|
+
export declare function isObservableMap<TKey, TItem>(value: any): value is jpfObservable.IObservableMap<TKey, TItem>;
|
|
16
|
+
export declare function isObservableSet<TItem>(value: any): value is jpfObservable.IObservableSet<TItem>;
|
|
17
|
+
export declare function computed<TComputed>(func: () => TComputed, options?: mobxIComputedValueOptions<TComputed>): jpfObservable.IComputed<TComputed>;
|
|
18
|
+
export declare function observableValue<TValue, TSetter = TValue>(value?: TValue | null, setter?: (value: TSetter, observableValue: jpfObservable.IObservableValue<TValue, TSetter>) => void, options?: mobxCreateObservableOptions): jpfObservable.IObservableValue<TValue, TSetter>;
|
|
19
|
+
export declare function observableArray<TItem = unknown, TSetter = Array<TItem>>(initialValues?: Array<TItem> | null, setter?: (value: TSetter, observableArray: jpfObservable.IObservableArray<TItem, TSetter>) => void, options?: mobxCreateObservableOptions): jpfObservable.IObservableArray<TItem, TSetter>;
|
|
20
|
+
export declare function observableMap<TKey = unknown, TItem = unknown>(initialValues?: mobxIMapEntries<TKey, TItem>, options?: mobxCreateObservableOptions): jpfObservable.IObservableMap<TKey, TItem>;
|
|
21
|
+
export declare function observableSet<TItem = unknown>(initialValues?: mobxIObservableSetInitialValues<TItem>, options?: mobxCreateObservableOptions): jpfObservable.IObservableSet<TItem>;
|
package/dist/observable.js
CHANGED
|
@@ -1,4 +1,49 @@
|
|
|
1
1
|
import { observable as mobxObservable, computed as mobxComputed, isComputed as mobxIsComputed, isBoxedObservable as mobxIsObservableValue, isObservableArray as mobxIsObservableArray, isObservableMap as mobxIsObservableMap, isObservableSet as mobxIsObservableSet, runInAction as mobxRunInAction, reaction as mobxReaction } from "mobx";
|
|
2
|
+
import { observable as jpfObservable } from "jpf";
|
|
3
|
+
function setDefaultOptions(target, source) {
|
|
4
|
+
if (source) {
|
|
5
|
+
target = target || {};
|
|
6
|
+
Object.keys(source).forEach((key) => {
|
|
7
|
+
if (!target.hasOwnProperty(key)) {
|
|
8
|
+
target[key] = source[key];
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
return target;
|
|
13
|
+
}
|
|
14
|
+
export function runInAction(fn) {
|
|
15
|
+
return mobxRunInAction(fn);
|
|
16
|
+
}
|
|
17
|
+
export function unwrap(value) {
|
|
18
|
+
if (mobxIsComputed(value) || mobxIsObservableValue(value)) {
|
|
19
|
+
return value.get();
|
|
20
|
+
}
|
|
21
|
+
if (mobxIsObservableArray(value)) {
|
|
22
|
+
return value.slice();
|
|
23
|
+
}
|
|
24
|
+
if (mobxIsObservableMap(value)) {
|
|
25
|
+
return new Map(value);
|
|
26
|
+
}
|
|
27
|
+
if (mobxIsObservableSet(value)) {
|
|
28
|
+
return new Set(value);
|
|
29
|
+
}
|
|
30
|
+
return value;
|
|
31
|
+
}
|
|
32
|
+
export function isComputed(value) {
|
|
33
|
+
return mobxIsComputed(value);
|
|
34
|
+
}
|
|
35
|
+
export function isObservableValue(value) {
|
|
36
|
+
return mobxIsObservableValue(value);
|
|
37
|
+
}
|
|
38
|
+
export function isObservableArray(value) {
|
|
39
|
+
return mobxIsObservableArray(value);
|
|
40
|
+
}
|
|
41
|
+
export function isObservableMap(value) {
|
|
42
|
+
return mobxIsObservableMap(value);
|
|
43
|
+
}
|
|
44
|
+
export function isObservableSet(value) {
|
|
45
|
+
return mobxIsObservableSet(value);
|
|
46
|
+
}
|
|
2
47
|
export function computed(func, options) {
|
|
3
48
|
const computed = mobxComputed(func, options);
|
|
4
49
|
const iComputed = computed;
|
|
@@ -11,9 +56,6 @@ export function computed(func, options) {
|
|
|
11
56
|
};
|
|
12
57
|
return iComputed;
|
|
13
58
|
}
|
|
14
|
-
export function runInAction(fn) {
|
|
15
|
-
return mobxRunInAction(fn);
|
|
16
|
-
}
|
|
17
59
|
export function observableValue(value, setter, options) {
|
|
18
60
|
setDefaultOptions(options, { deep: false });
|
|
19
61
|
const observableValue = mobxObservable.box(value || null, options);
|
|
@@ -98,52 +140,16 @@ export function observableSet(initialValues, options) {
|
|
|
98
140
|
options = { ...defaultOptions, ...options };
|
|
99
141
|
return mobxObservable.set(initialValues, options);
|
|
100
142
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
}
|
|
114
|
-
export function isObservableArray(value) {
|
|
115
|
-
return mobxIsObservableArray(value);
|
|
116
|
-
}
|
|
117
|
-
export function isObservableMap(value) {
|
|
118
|
-
return mobxIsObservableMap(value);
|
|
119
|
-
}
|
|
120
|
-
export function isObservableSet(value) {
|
|
121
|
-
return mobxIsObservableSet(value);
|
|
122
|
-
}
|
|
123
|
-
export function unwrap(value) {
|
|
124
|
-
if (mobxIsComputed(value) || mobxIsObservableValue(value)) {
|
|
125
|
-
return value.get();
|
|
126
|
-
}
|
|
127
|
-
if (mobxIsObservableArray(value)) {
|
|
128
|
-
return value.slice();
|
|
129
|
-
}
|
|
130
|
-
if (mobxIsObservableMap(value)) {
|
|
131
|
-
return new Map(value);
|
|
132
|
-
}
|
|
133
|
-
if (mobxIsObservableSet(value)) {
|
|
134
|
-
return new Set(value);
|
|
135
|
-
}
|
|
136
|
-
return value;
|
|
137
|
-
}
|
|
138
|
-
function setDefaultOptions(target, source) {
|
|
139
|
-
if (source) {
|
|
140
|
-
target = target || {};
|
|
141
|
-
Object.keys(source).forEach((key) => {
|
|
142
|
-
if (!target.hasOwnProperty(key)) {
|
|
143
|
-
target[key] = source[key];
|
|
144
|
-
}
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
return target;
|
|
148
|
-
}
|
|
143
|
+
const observable = jpfObservable.observable;
|
|
144
|
+
observable.unwrap = unwrap;
|
|
145
|
+
observable.isComputed = isComputed;
|
|
146
|
+
observable.isObservableValue = isObservableValue;
|
|
147
|
+
observable.isObservableArray = isObservableArray;
|
|
148
|
+
observable.isObservableMap = isObservableMap;
|
|
149
|
+
observable.isObservableSet = isObservableSet;
|
|
150
|
+
observable.computed = computed;
|
|
151
|
+
observable.observableValue = observableValue;
|
|
152
|
+
observable.observableArray = observableArray;
|
|
153
|
+
observable.observableMap = observableMap;
|
|
154
|
+
observable.observableSet = observableSet;
|
|
149
155
|
//# sourceMappingURL=observable.js.map
|
package/dist/observable.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"observable.js","sourceRoot":"","sources":["../src/observable.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"observable.js","sourceRoot":"","sources":["../src/observable.ts"],"names":[],"mappings":"AACA,OAAO,EACH,UAAU,IAAI,cAAc,EAC5B,QAAQ,IAAI,YAAY,EAExB,UAAU,IAAI,cAAc,EAE5B,iBAAiB,IAAI,qBAAqB,EAC1C,iBAAiB,IAAI,qBAAqB,EAC1C,eAAe,IAAI,mBAAmB,EACtC,eAAe,IAAI,mBAAmB,EACtC,WAAW,IAAI,eAAe,EAC9B,QAAQ,IAAI,YAAY,EAK3B,MAAM,MAAM,CAAC;AAEd,OAAO,EAAE,UAAU,IAAI,aAAa,EAAE,MAAM,KAAK,CAAC;AAElD,SAAS,iBAAiB,CAAW,MAAgB,EAAE,MAAgB;IACnE,IAAI,MAAM,EAAE,CAAC;QACT,MAAM,GAAG,MAAM,IAAI,EAAc,CAAC;QAClC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;YAChC,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE,CAAC;gBAC9B,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;YAC9B,CAAC;QACL,CAAC,CAAC,CAAC;IACP,CAAC;IAED,OAAO,MAAM,CAAC;AAClB,CAAC;AAED,MAAM,UAAU,WAAW,CAAI,EAAW;IACtC,OAAO,eAAe,CAAI,EAAE,CAAC,CAAC;AAClC,CAAC;AAUD,MAAM,UAAU,MAAM,CAAS,KAAmD;IAC9E,IAAI,cAAc,CAAC,KAAK,CAAC,IAAI,qBAAqB,CAAC,KAAK,CAAC,EAAE,CAAC;QACxD,OAAQ,KAAsC,CAAC,GAAG,EAAE,CAAC;IACzD,CAAC;IAED,IAAI,qBAAqB,CAAC,KAAK,CAAC,E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e,CAAC;AAC7C,UAAU,CAAC,eAAe,GAAG,eAAe,CAAC;AAC7C,UAAU,CAAC,QAAQ,GAAG,QAAQ,CAAA;AAC9B,UAAU,CAAC,eAAe,GAAG,eAAe,CAAC;AAC7C,UAAU,CAAC,eAAe,GAAG,eAAe,CAAC;AAC7C,UAAU,CAAC,aAAa,GAAG,aAAa,CAAC;AACzC,UAAU,CAAC,aAAa,GAAG,aAAa,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jpf-mobx",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.159",
|
|
4
4
|
"description": "Javascript Presentation Foundation with mobx state management",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mvvm",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"esLint": "npx eslint src/**"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"jpf": "5.0.
|
|
46
|
+
"jpf": "5.0.63",
|
|
47
47
|
"mobx": "6.15.0"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
package/src/index.ts
CHANGED
|
@@ -4,37 +4,24 @@
|
|
|
4
4
|
attributes,
|
|
5
5
|
element,
|
|
6
6
|
event,
|
|
7
|
-
observableInterfaces,
|
|
8
|
-
observableImplementations,
|
|
9
7
|
properties,
|
|
10
8
|
root,
|
|
11
9
|
style,
|
|
12
10
|
css
|
|
13
11
|
} from "jpf";
|
|
14
12
|
|
|
15
|
-
import
|
|
16
|
-
|
|
17
|
-
//Set the mobx implementations for the observable functions
|
|
18
|
-
observableImplementations.implementations.unwrap = unwrap;
|
|
19
|
-
observableImplementations.implementations.isComputed = isComputed;
|
|
20
|
-
observableImplementations.implementations.isObservableValue = isObservableValue;
|
|
21
|
-
observableImplementations.implementations.isObservableArray = isObservableArray;
|
|
22
|
-
observableImplementations.implementations.isObservableMap = isObservableMap;
|
|
23
|
-
observableImplementations.implementations.isObservableSet = isObservableSet;
|
|
24
|
-
observableImplementations.implementations.computed = computed;
|
|
25
|
-
observableImplementations.implementations.observableValue = observableValue;
|
|
26
|
-
observableImplementations.implementations.observableArray = observableArray;
|
|
27
|
-
observableImplementations.implementations.observableMap = observableMap;
|
|
28
|
-
observableImplementations.implementations.observableSet = observableSet;
|
|
13
|
+
import * as observable from "./observable";
|
|
29
14
|
|
|
15
|
+
//Export the Jpf modules
|
|
30
16
|
export { controls };
|
|
31
17
|
export { utilities };
|
|
32
18
|
export { attributes };
|
|
33
19
|
export { element };
|
|
34
20
|
export { event };
|
|
35
|
-
export { observableInterfaces }
|
|
36
21
|
export { properties };
|
|
37
22
|
export { root };
|
|
38
23
|
export { style };
|
|
39
24
|
export { css };
|
|
40
|
-
|
|
25
|
+
|
|
26
|
+
//Export the Jpf-Mobx observable module
|
|
27
|
+
export { observable };
|
package/src/observable.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
import {
|
|
2
3
|
observable as mobxObservable,
|
|
3
4
|
computed as mobxComputed,
|
|
4
5
|
IObservableValue as mobxIObservableValue,
|
|
@@ -11,18 +12,81 @@
|
|
|
11
12
|
runInAction as mobxRunInAction,
|
|
12
13
|
reaction as mobxReaction,
|
|
13
14
|
CreateObservableOptions as mobxCreateObservableOptions,
|
|
14
|
-
//IObservableMapInitialValues as mobxIObservableMapInitialValues,
|
|
15
15
|
IObservableSetInitialValues as mobxIObservableSetInitialValues,
|
|
16
16
|
IReactionPublic as mobxIReactionPublic,
|
|
17
17
|
IMapEntries as mobxIMapEntries
|
|
18
18
|
} from "mobx";
|
|
19
19
|
|
|
20
|
-
import {
|
|
20
|
+
import { observable as jpfObservable } from "jpf";
|
|
21
21
|
|
|
22
|
+
function setDefaultOptions<TOptions>(target: TOptions, source: TOptions): TOptions {
|
|
23
|
+
if (source) {
|
|
24
|
+
target = target || {} as TOptions;
|
|
25
|
+
Object.keys(source).forEach((key) => {
|
|
26
|
+
if (!target.hasOwnProperty(key)) {
|
|
27
|
+
target[key] = source[key];
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return target;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function runInAction<T>(fn: () => T): T {
|
|
36
|
+
return mobxRunInAction<T>(fn);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export type IComputed<TValue> = jpfObservable.IComputed<TValue>
|
|
40
|
+
export type IDisposer = jpfObservable.IDisposer
|
|
41
|
+
export type IObservableArray<TItem = any, TSetter = TItem[]> = jpfObservable.IObservableArray<TItem, TSetter>
|
|
42
|
+
export type IObservableMap<TKey = unknown, TItem = unknown> = jpfObservable.IObservableMap<TKey, TItem>
|
|
43
|
+
export type IObservableSet<TItem = unknown> = jpfObservable.IObservableSet<TItem>
|
|
44
|
+
export type IObservableValue<TValue, TSetter = TValue> = jpfObservable.IObservableValue<TValue, TSetter>
|
|
45
|
+
export type ISubscribable<TValue> = jpfObservable.ISubscribable<TValue>;
|
|
46
|
+
|
|
47
|
+
export function unwrap<TValue>(value: TValue | jpfObservable.ISubscribable<TValue>): TValue {
|
|
48
|
+
if (mobxIsComputed(value) || mobxIsObservableValue(value)) {
|
|
49
|
+
return (value as mobxIObservableValue<TValue>).get();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (mobxIsObservableArray(value)) {
|
|
53
|
+
return value.slice() as unknown as TValue;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (mobxIsObservableMap(value)) {
|
|
57
|
+
return new Map(value) as unknown as TValue;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (mobxIsObservableSet(value)) {
|
|
61
|
+
return new Set(value) as unknown as TValue;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return value as TValue;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function isComputed<TValue>(value: unknown): value is jpfObservable.IComputed<TValue> {
|
|
68
|
+
return mobxIsComputed(value);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function isObservableValue(value): value is jpfObservable.IObservableValue {
|
|
72
|
+
return mobxIsObservableValue(value);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function isObservableArray(value): value is jpfObservable.IObservableArray {
|
|
76
|
+
return mobxIsObservableArray(value);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function isObservableMap<TKey, TItem>(value): value is jpfObservable.IObservableMap<TKey, TItem> {
|
|
80
|
+
return mobxIsObservableMap(value);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function isObservableSet<TItem>(value): value is jpfObservable.IObservableSet<TItem> {
|
|
84
|
+
return mobxIsObservableSet(value);
|
|
85
|
+
}
|
|
22
86
|
|
|
23
|
-
export function computed<TComputed>(func: () => TComputed, options?: mobxIComputedValueOptions<TComputed>):
|
|
87
|
+
export function computed<TComputed>(func: () => TComputed, options?: mobxIComputedValueOptions<TComputed>): jpfObservable.IComputed<TComputed> {
|
|
24
88
|
const computed = mobxComputed(func, options);
|
|
25
|
-
const iComputed = computed as unknown as
|
|
89
|
+
const iComputed = computed as unknown as jpfObservable.IComputed<TComputed>;
|
|
26
90
|
|
|
27
91
|
iComputed.subscribe = (effect: (arg: TComputed, prev: TComputed, r: mobxIReactionPublic) => void) => {
|
|
28
92
|
return mobxReaction(
|
|
@@ -38,15 +102,11 @@ export function computed<TComputed>(func: () => TComputed, options?: mobxIComput
|
|
|
38
102
|
return iComputed;
|
|
39
103
|
}
|
|
40
104
|
|
|
41
|
-
export function
|
|
42
|
-
return mobxRunInAction<T>(fn);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export function observableValue<TValue, TSetter = TValue>(value?: TValue | null, setter?: (value: TSetter, observableValue: observableInterfaces.IObservableValue<TValue, TSetter>) => void, options?: mobxCreateObservableOptions): observableInterfaces.IObservableValue<TValue, TSetter> {
|
|
105
|
+
export function observableValue<TValue, TSetter = TValue>(value?: TValue | null, setter?: (value: TSetter, observableValue: jpfObservable.IObservableValue<TValue, TSetter>) => void, options?: mobxCreateObservableOptions): jpfObservable.IObservableValue<TValue, TSetter> {
|
|
46
106
|
//Make sure deep is set to false if not provided
|
|
47
107
|
setDefaultOptions(options, { deep: false });
|
|
48
108
|
|
|
49
|
-
const observableValue = mobxObservable.box(value || null, options) as unknown as
|
|
109
|
+
const observableValue = mobxObservable.box(value || null, options) as unknown as jpfObservable.IObservableValue<TValue, TSetter>;
|
|
50
110
|
|
|
51
111
|
observableValue.setValue = (newValue: TSetter) => {
|
|
52
112
|
if (newValue === undefined) {
|
|
@@ -92,11 +152,11 @@ export function observableValue<TValue, TSetter = TValue>(value?: TValue | null,
|
|
|
92
152
|
return observableValue;
|
|
93
153
|
}
|
|
94
154
|
|
|
95
|
-
export function observableArray<TItem = unknown, TSetter = Array<TItem>>(initialValues?: Array<TItem> | null, setter?: (value: TSetter, observableArray:
|
|
155
|
+
export function observableArray<TItem = unknown, TSetter = Array<TItem>>(initialValues?: Array<TItem> | null, setter?: (value: TSetter, observableArray: jpfObservable.IObservableArray<TItem, TSetter>) => void, options?: mobxCreateObservableOptions): jpfObservable.IObservableArray<TItem, TSetter> {
|
|
96
156
|
//Make sure deep is set to false if not provided
|
|
97
157
|
options = setDefaultOptions(options, { deep: false });
|
|
98
158
|
|
|
99
|
-
const observableArray = mobxObservable.array(initialValues || null, options) as unknown as
|
|
159
|
+
const observableArray = mobxObservable.array(initialValues || null, options) as unknown as jpfObservable.IObservableArray<TItem, TSetter>;
|
|
100
160
|
|
|
101
161
|
observableArray.setItems = (newValue: TSetter) => {
|
|
102
162
|
if (newValue === undefined) {
|
|
@@ -139,7 +199,7 @@ export function observableArray<TItem = unknown, TSetter = Array<TItem>>(initial
|
|
|
139
199
|
return observableArray;
|
|
140
200
|
}
|
|
141
201
|
|
|
142
|
-
export function observableMap<TKey = unknown, TItem = unknown>(initialValues?: mobxIMapEntries<TKey, TItem>, options?: mobxCreateObservableOptions):
|
|
202
|
+
export function observableMap<TKey = unknown, TItem = unknown>(initialValues?: mobxIMapEntries<TKey, TItem>, options?: mobxCreateObservableOptions): jpfObservable.IObservableMap<TKey, TItem> {
|
|
143
203
|
//Add a deep property if the property does not already exist
|
|
144
204
|
const defaultOptions = { deep: false };
|
|
145
205
|
options = { ...defaultOptions, ...options };
|
|
@@ -147,7 +207,7 @@ export function observableMap<TKey = unknown, TItem = unknown>(initialValues?: m
|
|
|
147
207
|
return mobxObservable.map<TKey, TItem>(initialValues, options);
|
|
148
208
|
}
|
|
149
209
|
|
|
150
|
-
export function observableSet<TItem = unknown>(initialValues?: mobxIObservableSetInitialValues<TItem>, options?: mobxCreateObservableOptions):
|
|
210
|
+
export function observableSet<TItem = unknown>(initialValues?: mobxIObservableSetInitialValues<TItem>, options?: mobxCreateObservableOptions): jpfObservable.IObservableSet<TItem> {
|
|
151
211
|
//Add a deep property if the property does not already exist
|
|
152
212
|
const defaultOptions = { deep: false };
|
|
153
213
|
options = { ...defaultOptions, ...options };
|
|
@@ -155,63 +215,18 @@ export function observableSet<TItem = unknown>(initialValues?: mobxIObservableSe
|
|
|
155
215
|
return mobxObservable.set<TItem>(initialValues, options);
|
|
156
216
|
}
|
|
157
217
|
|
|
158
|
-
export function isComputed<TValue>(value: unknown): value is observableInterfaces.IComputed<TValue> {
|
|
159
|
-
return mobxIsComputed(value);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
export function isSubscribable<TValue>(value: unknown): value is observableInterfaces.ISubscribable<TValue> {
|
|
163
|
-
return mobxIsComputed(value)
|
|
164
|
-
|| mobxIsObservableValue(value)
|
|
165
|
-
|| mobxIsObservableArray(value)
|
|
166
|
-
|| mobxIsObservableMap(value)
|
|
167
|
-
|| mobxIsObservableSet(value);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
export function isObservableValue(value): value is observableInterfaces.IObservableValue {
|
|
171
|
-
return mobxIsObservableValue(value);
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
export function isObservableArray(value): value is observableInterfaces.IObservableArray {
|
|
175
|
-
return mobxIsObservableArray(value);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
export function isObservableMap<TKey, TItem>(value): value is observableInterfaces.IObservableMap<TKey, TItem> {
|
|
179
|
-
return mobxIsObservableMap(value);
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
export function isObservableSet<TItem>(value): value is observableInterfaces.IObservableSet<TItem> {
|
|
183
|
-
return mobxIsObservableSet(value);
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
export function unwrap<TValue>(value: TValue | observableInterfaces.ISubscribable<TValue>): TValue {
|
|
187
|
-
if (mobxIsComputed(value) || mobxIsObservableValue(value)) {
|
|
188
|
-
return (value as mobxIObservableValue<TValue>).get();
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
if (mobxIsObservableArray(value)) {
|
|
192
|
-
return value.slice() as unknown as TValue;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
if (mobxIsObservableMap(value)) {
|
|
196
|
-
return new Map(value) as unknown as TValue;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
if (mobxIsObservableSet(value)) {
|
|
200
|
-
return new Set(value) as unknown as TValue;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
return value as TValue;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
function setDefaultOptions<TOptions>(target: TOptions, source: TOptions): TOptions {
|
|
207
|
-
if (source) {
|
|
208
|
-
target = target || {} as TOptions;
|
|
209
|
-
Object.keys(source).forEach((key) => {
|
|
210
|
-
if (!target.hasOwnProperty(key)) {
|
|
211
|
-
target[key] = source[key];
|
|
212
|
-
}
|
|
213
|
-
});
|
|
214
|
-
}
|
|
215
218
|
|
|
216
|
-
|
|
217
|
-
|
|
219
|
+
const observable = jpfObservable.observable;
|
|
220
|
+
|
|
221
|
+
//Overwrite jpf observable implementation with mobx implementation
|
|
222
|
+
observable.unwrap = unwrap;
|
|
223
|
+
observable.isComputed = isComputed;
|
|
224
|
+
observable.isObservableValue = isObservableValue;
|
|
225
|
+
observable.isObservableArray = isObservableArray;
|
|
226
|
+
observable.isObservableMap = isObservableMap;
|
|
227
|
+
observable.isObservableSet = isObservableSet;
|
|
228
|
+
observable.computed = computed
|
|
229
|
+
observable.observableValue = observableValue;
|
|
230
|
+
observable.observableArray = observableArray;
|
|
231
|
+
observable.observableMap = observableMap;
|
|
232
|
+
observable.observableSet = observableSet;
|