jpf-mobx 1.0.34 → 1.0.35
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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { computed, IObservableValue
|
|
1
|
+
import { computed, IObservableValue, IObservableArray as mobxObservableArray, ObservableMap as mobxObservableMap, ObservableSet as mobxObservableSet, action, CreateObservableOptions, IObservableMapInitialValues, IObservableSetInitialValues, IReactionPublic, IAutorunOptions, IReactionDisposer, IReactionOptions } from "mobx";
|
|
2
2
|
export interface ObservableValue<TValue = any, TSetter = TValue> extends Subscribable<TValue> {
|
|
3
3
|
setInternal(value: TValue): any;
|
|
4
4
|
}
|
|
@@ -16,10 +16,10 @@ export declare function observableValue<TValue, TSetter = TValue>(value?: null |
|
|
|
16
16
|
export declare function observableArray<TItem = any>(initialValues?: Array<TItem>, options?: CreateObservableOptions): mobxObservableArray<TItem>;
|
|
17
17
|
export declare function observableMap<TKey = any, TItem = any>(initialValues?: IObservableMapInitialValues<TKey, TItem>, options?: CreateObservableOptions): mobxObservableMap<TKey, TItem>;
|
|
18
18
|
export declare function observableSet<TItem = any>(initialValues?: IObservableSetInitialValues<TItem>, options?: CreateObservableOptions): mobxObservableSet<TItem>;
|
|
19
|
-
export interface Subscribable<TValue> extends
|
|
19
|
+
export interface Subscribable<TValue> extends IObservableValue<TValue> {
|
|
20
20
|
}
|
|
21
21
|
export declare function isSubscribable<TValue>(value: any): value is Subscribable<TValue>;
|
|
22
|
-
export declare function isObservableValue(value: any): value is
|
|
22
|
+
export declare function isObservableValue(value: any): value is IObservableValue<any>;
|
|
23
23
|
export declare function isObservableArray(value: any): boolean;
|
|
24
24
|
export declare function isObservableMap<TKey, TItem>(value: any): value is mobxObservableMap<TKey, TItem>;
|
|
25
25
|
export declare function isObservableSet<TItem>(value: any): value is mobxObservableSet<TItem>;
|
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import { observable, computed, isComputed, isBoxedObservable as mobxIsObservableValue, isObservableArray as mobxIsObservableArray, isObservableMap as mobxIsObservableMap, isObservableSet as mobxIsObservableSet, action, runInAction as mobxRunInAction, autorun as mobxAutorun, reaction as mobxReaction } from "mobx";
|
|
2
|
-
|
|
2
|
+
function setDefaultOptions(target, source) {
|
|
3
|
+
if (source) {
|
|
4
|
+
target = target || {};
|
|
5
|
+
Object.keys(source).forEach((key) => {
|
|
6
|
+
if (!target.hasOwnProperty(key)) {
|
|
7
|
+
target[key] = source[key];
|
|
8
|
+
}
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
return target;
|
|
12
|
+
}
|
|
3
13
|
export { computed, action };
|
|
4
14
|
export function autorun(view, opts) {
|
|
5
15
|
return mobxAutorun(view, opts);
|
|
@@ -8,7 +18,7 @@ export function runInAction(fn) {
|
|
|
8
18
|
return mobxRunInAction(fn);
|
|
9
19
|
}
|
|
10
20
|
export function reaction(expression, effect, opts) {
|
|
11
|
-
return mobxReaction(expression, effect);
|
|
21
|
+
return mobxReaction(expression, effect, opts);
|
|
12
22
|
}
|
|
13
23
|
export function observableValue(value, setter) {
|
|
14
24
|
var internalProperty = observable.box(value);
|
|
@@ -24,15 +34,15 @@ export function observableValue(value, setter) {
|
|
|
24
34
|
return internalProperty;
|
|
25
35
|
}
|
|
26
36
|
export function observableArray(initialValues, options) {
|
|
27
|
-
options =
|
|
37
|
+
options = setDefaultOptions(options, { deep: false });
|
|
28
38
|
return observable.array(initialValues, options);
|
|
29
39
|
}
|
|
30
40
|
export function observableMap(initialValues, options) {
|
|
31
|
-
options =
|
|
41
|
+
options = setDefaultOptions(options, { deep: false });
|
|
32
42
|
return observable.map(initialValues, options);
|
|
33
43
|
}
|
|
34
44
|
export function observableSet(initialValues, options) {
|
|
35
|
-
options =
|
|
45
|
+
options = setDefaultOptions(options, { deep: false });
|
|
36
46
|
return observable.set(initialValues, options);
|
|
37
47
|
}
|
|
38
48
|
export function isSubscribable(value) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"observable.js","sourceRoot":"","sources":["../../src/framework/observable.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,UAAU,EACV,QAAQ,EAKR,UAAU,EACV,iBAAiB,IAAI,qBAAqB,EAC1C,iBAAiB,IAAI,qBAAqB,EAC1C,eAAe,IAAI,mBAAmB,EACtC,eAAe,IAAI,mBAAmB,EACtC,MAAM,EACN,WAAW,IAAI,eAAe,EAC9B,OAAO,IAAI,WAAW,EACtB,QAAQ,IAAI,YAAY,EAQ3B,MAAM,MAAM,CAAC;AAEd,
|
|
1
|
+
{"version":3,"file":"observable.js","sourceRoot":"","sources":["../../src/framework/observable.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,UAAU,EACV,QAAQ,EAKR,UAAU,EACV,iBAAiB,IAAI,qBAAqB,EAC1C,iBAAiB,IAAI,qBAAqB,EAC1C,eAAe,IAAI,mBAAmB,EACtC,eAAe,IAAI,mBAAmB,EACtC,MAAM,EACN,WAAW,IAAI,eAAe,EAC9B,OAAO,IAAI,WAAW,EACtB,QAAQ,IAAI,YAAY,EAQ3B,MAAM,MAAM,CAAC;AAEd,SAAS,iBAAiB,CAAW,MAAgB,EAAE,MAAgB;IACnE,IAAI,MAAM,EAAE;QACR,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;gBAC7B,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;aAC7B;QACL,CAAC,CAAC,CAAC;KACN;IAED,OAAO,MAAM,CAAC;AAClB,CAAC;AAiBD,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;AAE5B,MAAM,UAAU,OAAO,CAAC,IAAiC,EAAE,IAAsB;IAC7E,OAAO,WAAW,CAAC,IAAI,EAAE,IAAI,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,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAC,OAAyB,EAAE,MAAc;IAE5E,IAAI,MAAM,CAAC,WAAW,KAAK,KAAK,EAAE;QAC9B,KAAK,MAAM,UAAU,IAAI,MAAoB,EAAE;YAC3C,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE;gBAChC,sBAAsB,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;aAC/C;SACJ;KACJ;SAAM;QAEH,IAAI,cAAc,CAAC,MAAM,CAAC,EAAE;YACxB,IAAI,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;YAC/B,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE;gBAC/B,sBAAsB,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;aAC9C;SACJ;aAAM;YAEH,OAAO,CAAC,MAAM,CAAC,CAAC;YAGhB,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE;gBACnC,MAAM,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;gBAC7B,IAAI,QAAQ,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE;oBAC1C,sBAAsB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;iBAC7C;aACJ;SACJ;KACJ;AACL,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
observable,
|
|
3
3
|
computed,
|
|
4
|
-
IObservableValue
|
|
4
|
+
IObservableValue,
|
|
5
5
|
IObservableArray as mobxObservableArray,
|
|
6
6
|
ObservableMap as mobxObservableMap,
|
|
7
7
|
ObservableSet as mobxObservableSet,
|
|
@@ -23,7 +23,18 @@
|
|
|
23
23
|
IReactionOptions
|
|
24
24
|
} from "mobx";
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
function setDefaultOptions<TOptions>(target: TOptions, source: TOptions): TOptions {
|
|
27
|
+
if (source) {
|
|
28
|
+
target = target || {} as TOptions;
|
|
29
|
+
Object.keys(source).forEach((key) => {
|
|
30
|
+
if (!target.hasOwnProperty(key)) {
|
|
31
|
+
target[key] = source[key];
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return target;
|
|
37
|
+
}
|
|
27
38
|
export interface ObservableValue<TValue = any, TSetter = TValue> extends Subscribable<TValue> {
|
|
28
39
|
setInternal(value: TValue);
|
|
29
40
|
}
|
|
@@ -51,7 +62,7 @@ export function runInAction<T>(fn: () => T): T {
|
|
|
51
62
|
}
|
|
52
63
|
|
|
53
64
|
export function reaction<T, FireImmediately extends boolean = false>(expression: (r: IReactionPublic) => T, effect: (arg: T, prev: FireImmediately extends true ? T | undefined : T, r: IReactionPublic) => void, opts?: IReactionOptions<T, FireImmediately>): IReactionDisposer {
|
|
54
|
-
return mobxReaction<T, FireImmediately>(expression, effect);
|
|
65
|
+
return mobxReaction<T, FireImmediately>(expression, effect, opts);
|
|
55
66
|
}
|
|
56
67
|
|
|
57
68
|
export function observableValue<TValue, TSetter = TValue>(value?: null | TValue, setter?: (value: TSetter, internalProperty: ObservableValue<TValue>) => void): ObservableValue<TValue> {
|
|
@@ -72,21 +83,21 @@ export function observableValue<TValue, TSetter = TValue>(value?: null | TValue,
|
|
|
72
83
|
}
|
|
73
84
|
|
|
74
85
|
export function observableArray<TItem = any>(initialValues?: Array<TItem>, options?: CreateObservableOptions): mobxObservableArray<TItem> {
|
|
75
|
-
options =
|
|
86
|
+
options = setDefaultOptions(options, { deep: false });
|
|
76
87
|
return observable.array(initialValues, options);
|
|
77
88
|
}
|
|
78
89
|
|
|
79
90
|
export function observableMap<TKey = any, TItem = any>(initialValues?: IObservableMapInitialValues<TKey, TItem>, options?: CreateObservableOptions) {
|
|
80
|
-
options =
|
|
91
|
+
options = setDefaultOptions(options, { deep: false });
|
|
81
92
|
return observable.map<TKey, TItem>(initialValues, options);
|
|
82
93
|
}
|
|
83
94
|
|
|
84
95
|
export function observableSet<TItem = any>(initialValues?: IObservableSetInitialValues<TItem>, options?: CreateObservableOptions) {
|
|
85
|
-
options =
|
|
96
|
+
options = setDefaultOptions(options, { deep: false });
|
|
86
97
|
return observable.set<TItem>(initialValues, options);
|
|
87
98
|
}
|
|
88
99
|
|
|
89
|
-
export interface Subscribable<TValue> extends
|
|
100
|
+
export interface Subscribable<TValue> extends IObservableValue<TValue> {
|
|
90
101
|
|
|
91
102
|
}
|
|
92
103
|
|
|
@@ -98,7 +109,7 @@ export function isSubscribable<TValue>(value: any): value is Subscribable<TValue
|
|
|
98
109
|
|| mobxIsObservableSet(value);
|
|
99
110
|
}
|
|
100
111
|
|
|
101
|
-
export function isObservableValue(value): value is
|
|
112
|
+
export function isObservableValue(value): value is IObservableValue<any> {
|
|
102
113
|
return mobxIsObservableValue(value);
|
|
103
114
|
}
|
|
104
115
|
|
|
@@ -115,19 +126,19 @@ export function isObservableSet<TItem>(value): value is mobxObservableSet<TItem>
|
|
|
115
126
|
}
|
|
116
127
|
export function unwrap<TValue>(value: TValue | Subscribable<TValue>): TValue {
|
|
117
128
|
if (isComputed(value) || mobxIsObservableValue(value)) {
|
|
118
|
-
return (value as
|
|
129
|
+
return (value as IObservableValue<TValue>).get();
|
|
119
130
|
}
|
|
120
131
|
|
|
121
132
|
if (mobxIsObservableArray(value)) {
|
|
122
|
-
return value.slice() as TValue;
|
|
133
|
+
return value.slice() as any as TValue;
|
|
123
134
|
}
|
|
124
135
|
|
|
125
136
|
if (mobxIsObservableMap(value)) {
|
|
126
|
-
return new Map(value) as TValue;
|
|
137
|
+
return new Map(value) as any as TValue;
|
|
127
138
|
}
|
|
128
139
|
|
|
129
140
|
if (mobxIsObservableSet(value)) {
|
|
130
|
-
return new Set(value) as TValue;
|
|
141
|
+
return new Set(value) as any as TValue;
|
|
131
142
|
}
|
|
132
143
|
|
|
133
144
|
return value;
|