@quantform/core 0.7.0-beta.13 → 0.7.0-beta.14
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/asset/asset.d.ts +3 -0
- package/dist/asset/asset.d.ts.map +1 -1
- package/dist/asset/asset.js +7 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/instrument/instrument.d.ts +3 -0
- package/dist/instrument/instrument.d.ts.map +1 -1
- package/dist/instrument/instrument.js +7 -1
- package/dist/replay/with-replay.js +2 -2
- package/dist/session/use-session-storage.js +2 -2
- package/dist/session/use-session.js +2 -2
- package/dist/storage/use-storage.js +2 -2
- package/dist/use-lock.js +2 -2
- package/dist/use-logger.js +2 -2
- package/dist/with-memo.d.ts +5 -0
- package/dist/with-memo.d.ts.map +1 -0
- package/dist/{use.js → with-memo.js} +3 -3
- package/dist/with-memo.spec.d.ts +2 -0
- package/dist/with-memo.spec.d.ts.map +1 -0
- package/dist/{use.spec.js → with-memo.spec.js} +3 -3
- package/package.json +1 -1
- package/src/asset/asset.ts +6 -0
- package/src/index.ts +1 -1
- package/src/instrument/instrument.ts +6 -0
- package/src/replay/with-replay.ts +2 -2
- package/src/session/use-session-storage.ts +2 -2
- package/src/session/use-session.ts +2 -2
- package/src/storage/use-storage.ts +2 -2
- package/src/use-lock.ts +2 -2
- package/src/use-logger.ts +2 -2
- package/src/{use.spec.ts → with-memo.spec.ts} +3 -3
- package/src/{use.ts → with-memo.ts} +3 -3
- package/dist/use.d.ts +0 -5
- package/dist/use.d.ts.map +0 -1
- package/dist/use.spec.d.ts +0 -2
- package/dist/use.spec.d.ts.map +0 -1
package/dist/asset/asset.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { decimal } from '../shared';
|
|
2
2
|
export declare const AssetSelectorSeparator = ":";
|
|
3
|
+
export declare class MissingAssetError extends Error {
|
|
4
|
+
constructor(asset: AssetSelector);
|
|
5
|
+
}
|
|
3
6
|
/**
|
|
4
7
|
* Supposed to query specific @see Asset based on string notation.
|
|
5
8
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asset.d.ts","sourceRoot":"","sources":["../../src/asset/asset.ts"],"names":[],"mappings":"AACA,OAAO,EAAK,OAAO,EAAE,MAAM,aAAa,CAAC;AAEzC,eAAO,MAAM,sBAAsB,MAAM,CAAC;AAE1C;;GAEG;AACH,qBAAa,aAAa;IACxB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;gBAEjB,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM;IAc7C,QAAQ;CAGT;AAED;;GAEG;AACH,wBAAgB,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG,aAAa,CAQvD;AAED;;;GAGG;AACH,qBAAa,KAAM,SAAQ,aAAa;aAGyB,KAAK,EAAE,MAAM;IAF5E,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;gBAEf,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAkB,KAAK,EAAE,MAAM;IAU5E;;OAEG;IACH,KAAK,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM;IAI9B;;OAEG;IACH,KAAK,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO;IAI/B;;OAEG;IACH,IAAI,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO;CAG/B"}
|
|
1
|
+
{"version":3,"file":"asset.d.ts","sourceRoot":"","sources":["../../src/asset/asset.ts"],"names":[],"mappings":"AACA,OAAO,EAAK,OAAO,EAAE,MAAM,aAAa,CAAC;AAEzC,eAAO,MAAM,sBAAsB,MAAM,CAAC;AAE1C,qBAAa,iBAAkB,SAAQ,KAAK;gBAC9B,KAAK,EAAE,aAAa;CAGjC;AAED;;GAEG;AACH,qBAAa,aAAa;IACxB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;gBAEjB,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM;IAc7C,QAAQ;CAGT;AAED;;GAEG;AACH,wBAAgB,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG,aAAa,CAQvD;AAED;;;GAGG;AACH,qBAAa,KAAM,SAAQ,aAAa;aAGyB,KAAK,EAAE,MAAM;IAF5E,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;gBAEf,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAkB,KAAK,EAAE,MAAM;IAU5E;;OAEG;IACH,KAAK,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM;IAI9B;;OAEG;IACH,KAAK,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO;IAI/B;;OAEG;IACH,IAAI,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO;CAG/B"}
|
package/dist/asset/asset.js
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Asset = exports.assetOf = exports.AssetSelector = exports.AssetSelectorSeparator = void 0;
|
|
3
|
+
exports.Asset = exports.assetOf = exports.AssetSelector = exports.MissingAssetError = exports.AssetSelectorSeparator = void 0;
|
|
4
4
|
const component_1 = require("../component");
|
|
5
5
|
const shared_1 = require("../shared");
|
|
6
6
|
exports.AssetSelectorSeparator = ':';
|
|
7
|
+
class MissingAssetError extends Error {
|
|
8
|
+
constructor(asset) {
|
|
9
|
+
super(`Missing asset: ${asset}`);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.MissingAssetError = MissingAssetError;
|
|
7
13
|
/**
|
|
8
14
|
* Supposed to query specific @see Asset based on string notation.
|
|
9
15
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ export * from './use-socket';
|
|
|
19
19
|
export * from './use-request';
|
|
20
20
|
export * from './defined';
|
|
21
21
|
export * from './as-readonly';
|
|
22
|
-
export * from './
|
|
22
|
+
export * from './with-memo';
|
|
23
23
|
export * from './session';
|
|
24
24
|
export * from './exclude';
|
|
25
25
|
export * from './use-lock';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oCAAoC,CAAC;AACnD,cAAc,yBAAyB,CAAC;AACxC,cAAc,0BAA0B,CAAC;AACzC,cAAc,wBAAwB,CAAC;AACvC,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,oCAAoC,CAAC;AACnD,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oCAAoC,CAAC;AACnD,cAAc,yBAAyB,CAAC;AACxC,cAAc,0BAA0B,CAAC;AACzC,cAAc,wBAAwB,CAAC;AACvC,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,oCAAoC,CAAC;AACnD,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -35,7 +35,7 @@ __exportStar(require("./use-socket"), exports);
|
|
|
35
35
|
__exportStar(require("./use-request"), exports);
|
|
36
36
|
__exportStar(require("./defined"), exports);
|
|
37
37
|
__exportStar(require("./as-readonly"), exports);
|
|
38
|
-
__exportStar(require("./
|
|
38
|
+
__exportStar(require("./with-memo"), exports);
|
|
39
39
|
__exportStar(require("./session"), exports);
|
|
40
40
|
__exportStar(require("./exclude"), exports);
|
|
41
41
|
__exportStar(require("./use-lock"), exports);
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { Asset, AssetSelector } from '../asset';
|
|
2
2
|
import { Commission } from './commission/commission';
|
|
3
3
|
export declare const InstrumentSelectorSeparator = "-";
|
|
4
|
+
export declare class MissingInstrumentError extends Error {
|
|
5
|
+
constructor(instrument: InstrumentSelector);
|
|
6
|
+
}
|
|
4
7
|
export declare class InstrumentSelector {
|
|
5
8
|
readonly id: string;
|
|
6
9
|
readonly base: AssetSelector;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instrument.d.ts","sourceRoot":"","sources":["../../src/instrument/instrument.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,aAAa,EAA0B,MAAM,YAAY,CAAC;AAG1E,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAErD,eAAO,MAAM,2BAA2B,MAAM,CAAC;AAE/C,qBAAa,kBAAkB;IAC7B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;IAC7B,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC;gBAElB,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;IAOxD,QAAQ;CAGT;AAED;;GAEG;AACH,qBAAa,UAAW,SAAQ,kBAAkB;IAKvC,SAAS,EAAE,MAAM;aACN,IAAI,EAAE,KAAK;aACX,KAAK,EAAE,KAAK;IAC9B,QAAQ,CAAC,GAAG,EAAE,MAAM;IACb,UAAU,EAAE,UAAU;IAR/B,QAAQ,CAAC,KAAK,EAAE,UAAU,GAAG,SAAS,CAAC;IACvC,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAa;gBAGhC,SAAS,EAAE,MAAM,EACN,IAAI,EAAE,KAAK,EACX,KAAK,EAAE,KAAK,EACrB,GAAG,EAAE,MAAM,EACb,UAAU,EAAE,UAAU;CAQhC;AAED,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,kBAAkB,CAYjE"}
|
|
1
|
+
{"version":3,"file":"instrument.d.ts","sourceRoot":"","sources":["../../src/instrument/instrument.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,aAAa,EAA0B,MAAM,YAAY,CAAC;AAG1E,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAErD,eAAO,MAAM,2BAA2B,MAAM,CAAC;AAE/C,qBAAa,sBAAuB,SAAQ,KAAK;gBACnC,UAAU,EAAE,kBAAkB;CAG3C;AAED,qBAAa,kBAAkB;IAC7B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;IAC7B,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC;gBAElB,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;IAOxD,QAAQ;CAGT;AAED;;GAEG;AACH,qBAAa,UAAW,SAAQ,kBAAkB;IAKvC,SAAS,EAAE,MAAM;aACN,IAAI,EAAE,KAAK;aACX,KAAK,EAAE,KAAK;IAC9B,QAAQ,CAAC,GAAG,EAAE,MAAM;IACb,UAAU,EAAE,UAAU;IAR/B,QAAQ,CAAC,KAAK,EAAE,UAAU,GAAG,SAAS,CAAC;IACvC,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAa;gBAGhC,SAAS,EAAE,MAAM,EACN,IAAI,EAAE,KAAK,EACX,KAAK,EAAE,KAAK,EACrB,GAAG,EAAE,MAAM,EACb,UAAU,EAAE,UAAU;CAQhC;AAED,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,kBAAkB,CAYjE"}
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.instrumentOf = exports.Instrument = exports.InstrumentSelector = exports.InstrumentSelectorSeparator = void 0;
|
|
3
|
+
exports.instrumentOf = exports.Instrument = exports.InstrumentSelector = exports.MissingInstrumentError = exports.InstrumentSelectorSeparator = void 0;
|
|
4
4
|
const asset_1 = require("../asset");
|
|
5
5
|
const component_1 = require("../component");
|
|
6
6
|
exports.InstrumentSelectorSeparator = '-';
|
|
7
|
+
class MissingInstrumentError extends Error {
|
|
8
|
+
constructor(instrument) {
|
|
9
|
+
super(`Missing instrument: ${instrument}`);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.MissingInstrumentError = MissingInstrumentError;
|
|
7
13
|
class InstrumentSelector {
|
|
8
14
|
constructor(base, quote, adapter) {
|
|
9
15
|
this.base = new asset_1.AssetSelector(base.toLowerCase(), adapter.toLowerCase());
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.withReplay = void 0;
|
|
4
|
-
const
|
|
4
|
+
const with_memo_1 = require("../with-memo");
|
|
5
5
|
function withReplay(fn) {
|
|
6
|
-
return (0,
|
|
6
|
+
return (0, with_memo_1.withMemo)(fn);
|
|
7
7
|
}
|
|
8
8
|
exports.withReplay = withReplay;
|
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.useSessionStorage = void 0;
|
|
4
4
|
const session_1 = require("../session");
|
|
5
5
|
const storage_1 = require("../storage");
|
|
6
|
-
const
|
|
7
|
-
exports.useSessionStorage = (0,
|
|
6
|
+
const with_memo_1 = require("../with-memo");
|
|
7
|
+
exports.useSessionStorage = (0, with_memo_1.withMemo)(() => {
|
|
8
8
|
const { id } = (0, session_1.useSession)();
|
|
9
9
|
return (0, storage_1.useStorage)(['session', id]);
|
|
10
10
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useSession = void 0;
|
|
4
|
-
const
|
|
5
|
-
exports.useSession = (0,
|
|
4
|
+
const with_memo_1 = require("../with-memo");
|
|
5
|
+
exports.useSession = (0, with_memo_1.withMemo)(() => ({
|
|
6
6
|
id: 'ttt' //Date.now()
|
|
7
7
|
}));
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useStorage = void 0;
|
|
4
|
-
const
|
|
4
|
+
const with_memo_1 = require("../with-memo");
|
|
5
5
|
const use_hash_1 = require("../use-hash");
|
|
6
6
|
const use_storage_factory_1 = require("./use-storage-factory");
|
|
7
|
-
exports.useStorage = (0,
|
|
7
|
+
exports.useStorage = (0, with_memo_1.withMemo)((dependencies) => {
|
|
8
8
|
const key = (0, use_hash_1.useHash)(dependencies);
|
|
9
9
|
const factory = (0, use_storage_factory_1.useStorageFactory)();
|
|
10
10
|
return factory.for(key);
|
package/dist/use-lock.js
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.exclusive = exports.useExclusiveLock = void 0;
|
|
4
4
|
const rxjs_1 = require("rxjs");
|
|
5
|
-
const
|
|
5
|
+
const with_memo_1 = require("./with-memo");
|
|
6
6
|
const use_hash_1 = require("./use-hash");
|
|
7
|
-
exports.useExclusiveLock = (0,
|
|
7
|
+
exports.useExclusiveLock = (0, with_memo_1.withMemo)(() => {
|
|
8
8
|
const locking = {};
|
|
9
9
|
const acquire = (dependencies) => {
|
|
10
10
|
const hash = (0, use_hash_1.useHash)(dependencies);
|
package/dist/use-logger.js
CHANGED
|
@@ -5,8 +5,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.useLogger = void 0;
|
|
7
7
|
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
-
const use_1 = require("./use");
|
|
9
8
|
const use_timestamp_1 = require("./use-timestamp");
|
|
9
|
+
const with_memo_1 = require("./with-memo");
|
|
10
10
|
const colorize = (content) => {
|
|
11
11
|
let hash = 0x811c9dc5;
|
|
12
12
|
for (let i = 0; i < content.length; i++) {
|
|
@@ -18,7 +18,7 @@ const colorize = (content) => {
|
|
|
18
18
|
/**
|
|
19
19
|
*
|
|
20
20
|
*/
|
|
21
|
-
exports.useLogger = (0,
|
|
21
|
+
exports.useLogger = (0, with_memo_1.withMemo)((context, tint) => {
|
|
22
22
|
const prefix = () => `${chalk_1.default.gray(new Date((0, use_timestamp_1.useTimestamp)()).toISOString())} ${chalk_1.default.hex(tint !== null && tint !== void 0 ? tint : colorize(context))(context)}`;
|
|
23
23
|
return {
|
|
24
24
|
info: (message, ...params) => (params === null || params === void 0 ? void 0 : params.length)
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Observable } from 'rxjs';
|
|
2
|
+
import { dependency } from './use-hash';
|
|
3
|
+
export declare function withMemo<T extends Array<dependency>, U>(fn: (...args: T) => U): (...args: T) => U;
|
|
4
|
+
export declare function withMemo<T extends Array<dependency>, U>(fn: (...args: T) => Observable<U>): (...args: T) => Observable<U>;
|
|
5
|
+
//# sourceMappingURL=with-memo.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"with-memo.d.ts","sourceRoot":"","sources":["../src/with-memo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,UAAU,EAAe,MAAM,MAAM,CAAC;AAK7D,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAGxC,wBAAgB,QAAQ,CAAC,CAAC,SAAS,KAAK,CAAC,UAAU,CAAC,EAAE,CAAC,EACrD,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,CAAC,GACpB,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC;AACrB,wBAAgB,QAAQ,CAAC,CAAC,SAAS,KAAK,CAAC,UAAU,CAAC,EAAE,CAAC,EACrD,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,UAAU,CAAC,CAAC,CAAC,GAChC,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,UAAU,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.withMemo = void 0;
|
|
4
4
|
const rxjs_1 = require("rxjs");
|
|
5
5
|
const uuid_1 = require("uuid");
|
|
6
6
|
const as_readonly_1 = require("./as-readonly");
|
|
7
7
|
const module_1 = require("./module");
|
|
8
8
|
const use_memo_1 = require("./use-memo");
|
|
9
|
-
function
|
|
9
|
+
function withMemo(fn) {
|
|
10
10
|
(0, module_1.throwWithContext)();
|
|
11
11
|
const uniqueId = (0, uuid_1.v4)();
|
|
12
12
|
return (...args) => (0, use_memo_1.useMemo)(() => {
|
|
@@ -17,4 +17,4 @@ function use(fn) {
|
|
|
17
17
|
return value;
|
|
18
18
|
}, [uniqueId, ...args]);
|
|
19
19
|
}
|
|
20
|
-
exports.
|
|
20
|
+
exports.withMemo = withMemo;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"with-memo.spec.d.ts","sourceRoot":"","sources":["../src/with-memo.spec.ts"],"names":[],"mappings":""}
|
|
@@ -11,8 +11,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
const make_test_module_1 = require("./make-test-module");
|
|
13
13
|
const instrument_1 = require("./instrument");
|
|
14
|
-
const
|
|
15
|
-
describe(
|
|
14
|
+
const with_memo_1 = require("./with-memo");
|
|
15
|
+
describe(with_memo_1.withMemo.name, () => {
|
|
16
16
|
let fixtures;
|
|
17
17
|
beforeEach(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
18
|
fixtures = yield getFixtures();
|
|
@@ -38,7 +38,7 @@ describe(use_1.use.name, () => {
|
|
|
38
38
|
function getFixtures() {
|
|
39
39
|
return __awaiter(this, void 0, void 0, function* () {
|
|
40
40
|
const { act } = yield (0, make_test_module_1.makeTestModule)([]);
|
|
41
|
-
const getValue = (0,
|
|
41
|
+
const getValue = (0, with_memo_1.withMemo)((instrument) => instrument.id);
|
|
42
42
|
return {
|
|
43
43
|
act,
|
|
44
44
|
getValue: act(() => (instrument) => getValue(instrument))
|
package/package.json
CHANGED
package/src/asset/asset.ts
CHANGED
|
@@ -3,6 +3,12 @@ import { d, decimal } from '@lib/shared';
|
|
|
3
3
|
|
|
4
4
|
export const AssetSelectorSeparator = ':';
|
|
5
5
|
|
|
6
|
+
export class MissingAssetError extends Error {
|
|
7
|
+
constructor(asset: AssetSelector) {
|
|
8
|
+
super(`Missing asset: ${asset}`);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
6
12
|
/**
|
|
7
13
|
* Supposed to query specific @see Asset based on string notation.
|
|
8
14
|
*/
|
package/src/index.ts
CHANGED
|
@@ -19,7 +19,7 @@ export * from '@lib/use-socket';
|
|
|
19
19
|
export * from '@lib/use-request';
|
|
20
20
|
export * from '@lib/defined';
|
|
21
21
|
export * from '@lib/as-readonly';
|
|
22
|
-
export * from '@lib/
|
|
22
|
+
export * from '@lib/with-memo';
|
|
23
23
|
export * from '@lib/session';
|
|
24
24
|
export * from '@lib/exclude';
|
|
25
25
|
export * from '@lib/use-lock';
|
|
@@ -5,6 +5,12 @@ import { Commission } from './commission/commission';
|
|
|
5
5
|
|
|
6
6
|
export const InstrumentSelectorSeparator = '-';
|
|
7
7
|
|
|
8
|
+
export class MissingInstrumentError extends Error {
|
|
9
|
+
constructor(instrument: InstrumentSelector) {
|
|
10
|
+
super(`Missing instrument: ${instrument}`);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
8
14
|
export class InstrumentSelector {
|
|
9
15
|
readonly id: string;
|
|
10
16
|
readonly base: AssetSelector;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Observable } from 'rxjs';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { withMemo } from '@lib/with-memo';
|
|
4
4
|
import { dependency } from '@lib/use-hash';
|
|
5
5
|
|
|
6
6
|
export function withReplay<T extends Array<dependency>, U extends Observable<K>, K>(
|
|
7
7
|
fn: (...args: T) => U
|
|
8
8
|
): (...args: T) => U {
|
|
9
|
-
return
|
|
9
|
+
return withMemo(fn);
|
|
10
10
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { useSession } from '@lib/session';
|
|
2
2
|
import { useStorage } from '@lib/storage';
|
|
3
|
-
import {
|
|
3
|
+
import { withMemo } from '@lib/with-memo';
|
|
4
4
|
|
|
5
|
-
export const useSessionStorage =
|
|
5
|
+
export const useSessionStorage = withMemo(() => {
|
|
6
6
|
const { id } = useSession();
|
|
7
7
|
|
|
8
8
|
return useStorage(['session', id]);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { withMemo } from '@lib/with-memo';
|
|
2
2
|
import { dependency, useHash } from '@lib/use-hash';
|
|
3
3
|
|
|
4
4
|
import { useStorageFactory } from './use-storage-factory';
|
|
5
5
|
|
|
6
|
-
export const useStorage =
|
|
6
|
+
export const useStorage = withMemo((dependencies: dependency[]) => {
|
|
7
7
|
const key = useHash(dependencies);
|
|
8
8
|
const factory = useStorageFactory();
|
|
9
9
|
|
package/src/use-lock.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { filter, finalize, Observable } from 'rxjs';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { withMemo } from '@lib/with-memo';
|
|
4
4
|
import { dependency, useHash } from '@lib/use-hash';
|
|
5
5
|
|
|
6
|
-
export const useExclusiveLock =
|
|
6
|
+
export const useExclusiveLock = withMemo(() => {
|
|
7
7
|
const locking = {} as Record<string, boolean>;
|
|
8
8
|
const acquire = (dependencies: dependency[]) => {
|
|
9
9
|
const hash = useHash(dependencies);
|
package/src/use-logger.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import chalk from 'chalk';
|
|
2
2
|
|
|
3
|
-
import { use } from './use';
|
|
4
3
|
import { useTimestamp } from './use-timestamp';
|
|
4
|
+
import { withMemo } from './with-memo';
|
|
5
5
|
|
|
6
6
|
const colorize = (content: string) => {
|
|
7
7
|
let hash = 0x811c9dc5;
|
|
@@ -17,7 +17,7 @@ const colorize = (content: string) => {
|
|
|
17
17
|
/**
|
|
18
18
|
*
|
|
19
19
|
*/
|
|
20
|
-
export const useLogger =
|
|
20
|
+
export const useLogger = withMemo((context: string, tint?: string) => {
|
|
21
21
|
const prefix = () =>
|
|
22
22
|
`${chalk.gray(new Date(useTimestamp()).toISOString())} ${chalk.hex(
|
|
23
23
|
tint ?? colorize(context)
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { makeTestModule } from '@lib/make-test-module';
|
|
2
2
|
|
|
3
3
|
import { instrumentOf, InstrumentSelector } from './instrument';
|
|
4
|
-
import {
|
|
4
|
+
import { withMemo } from './with-memo';
|
|
5
5
|
|
|
6
|
-
describe(
|
|
6
|
+
describe(withMemo.name, () => {
|
|
7
7
|
let fixtures: Awaited<ReturnType<typeof getFixtures>>;
|
|
8
8
|
|
|
9
9
|
beforeEach(async () => {
|
|
@@ -37,7 +37,7 @@ describe(use.name, () => {
|
|
|
37
37
|
async function getFixtures() {
|
|
38
38
|
const { act } = await makeTestModule([]);
|
|
39
39
|
|
|
40
|
-
const getValue =
|
|
40
|
+
const getValue = withMemo((instrument: InstrumentSelector) => instrument.id);
|
|
41
41
|
|
|
42
42
|
return {
|
|
43
43
|
act,
|
|
@@ -6,14 +6,14 @@ import { throwWithContext } from './module';
|
|
|
6
6
|
import { dependency } from './use-hash';
|
|
7
7
|
import { useMemo } from './use-memo';
|
|
8
8
|
|
|
9
|
-
export function
|
|
9
|
+
export function withMemo<T extends Array<dependency>, U>(
|
|
10
10
|
fn: (...args: T) => U
|
|
11
11
|
): (...args: T) => U;
|
|
12
|
-
export function
|
|
12
|
+
export function withMemo<T extends Array<dependency>, U>(
|
|
13
13
|
fn: (...args: T) => Observable<U>
|
|
14
14
|
): (...args: T) => Observable<U>;
|
|
15
15
|
|
|
16
|
-
export function
|
|
16
|
+
export function withMemo<T extends Array<dependency>, U>(
|
|
17
17
|
fn: (...args: T) => U | Observable<U>
|
|
18
18
|
): (...args: T) => U | Observable<U> {
|
|
19
19
|
throwWithContext();
|
package/dist/use.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { Observable } from 'rxjs';
|
|
2
|
-
import { dependency } from './use-hash';
|
|
3
|
-
export declare function use<T extends Array<dependency>, U>(fn: (...args: T) => U): (...args: T) => U;
|
|
4
|
-
export declare function use<T extends Array<dependency>, U>(fn: (...args: T) => Observable<U>): (...args: T) => Observable<U>;
|
|
5
|
-
//# sourceMappingURL=use.d.ts.map
|
package/dist/use.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use.d.ts","sourceRoot":"","sources":["../src/use.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,UAAU,EAAe,MAAM,MAAM,CAAC;AAK7D,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAGxC,wBAAgB,GAAG,CAAC,CAAC,SAAS,KAAK,CAAC,UAAU,CAAC,EAAE,CAAC,EAChD,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,CAAC,GACpB,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC;AACrB,wBAAgB,GAAG,CAAC,CAAC,SAAS,KAAK,CAAC,UAAU,CAAC,EAAE,CAAC,EAChD,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,UAAU,CAAC,CAAC,CAAC,GAChC,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,UAAU,CAAC,CAAC,CAAC,CAAC"}
|
package/dist/use.spec.d.ts
DELETED
package/dist/use.spec.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use.spec.d.ts","sourceRoot":"","sources":["../src/use.spec.ts"],"names":[],"mappings":""}
|