增加了subscriber的声明及整体构架
This commit is contained in:
parent
244c065f61
commit
7096ca51b6
|
|
@ -1,4 +1,4 @@
|
|||
import { EntityDict, OperateOption, SelectOption, OpRecord, AspectWrapper, CheckerType, Aspect, StorageSchema, Checker } from 'oak-domain/lib/types';
|
||||
import { EntityDict, OperateOption, SelectOption, OpRecord, AspectWrapper, CheckerType, Aspect, StorageSchema, Checker, SubDataDef } from 'oak-domain/lib/types';
|
||||
import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain';
|
||||
import { CommonAspectDict } from 'oak-common-aspect';
|
||||
import { Feature } from '../types/Feature';
|
||||
|
|
@ -88,5 +88,7 @@ export declare class Cache<ED extends EntityDict & BaseEntityDict, Cxt extends A
|
|||
commit(): void;
|
||||
rollback(): void;
|
||||
buildContext(): FrontCxt;
|
||||
sub(data: Array<SubDataDef<ED, keyof ED>>, callback: (records: OpRecord<ED>[], ids: string[]) => void): Promise<void>;
|
||||
unsub(ids: string[]): Promise<void>;
|
||||
}
|
||||
export {};
|
||||
|
|
|
|||
|
|
@ -604,6 +604,16 @@ var Cache = /** @class */ (function (_super) {
|
|||
Cache.prototype.buildContext = function () {
|
||||
return this.contextBuilder();
|
||||
};
|
||||
Cache.prototype.sub = function (data, callback) {
|
||||
var _this = this;
|
||||
return this.aspectWrapper.sub(data, function (records, ids) {
|
||||
_this.sync(records),
|
||||
callback(records, ids);
|
||||
});
|
||||
};
|
||||
Cache.prototype.unsub = function (ids) {
|
||||
return this.aspectWrapper.unsub(ids);
|
||||
};
|
||||
return Cache;
|
||||
}(Feature_1.Feature));
|
||||
exports.Cache = Cache;
|
||||
|
|
|
|||
|
|
@ -73,6 +73,17 @@ function initialize(storageSchema, frontendContextBuilder, backendContextBuilder
|
|||
}
|
||||
});
|
||||
}); },
|
||||
/**
|
||||
* dev模式下订阅数据没有意义(单用户模式)
|
||||
* @param data
|
||||
* @returns
|
||||
*/
|
||||
sub: function (data, callback) {
|
||||
return Promise.resolve();
|
||||
},
|
||||
unsub: function (ids) {
|
||||
return Promise.resolve();
|
||||
},
|
||||
};
|
||||
var features2 = (0, features_1.initializeStep2)(features1, wrapper, storageSchema, frontendContextBuilder, checkers2, actionCascadePathGraph, relationCascadePathGraph, authDeduceRelationMap, colorDict, function () { return debugStore.getCurrentData(); }, undefined, selectFreeEntities, createFreeEntities, updateFreeEntities, cacheSavedEntities, cacheKeepFreshPeriod);
|
||||
(0, oak_common_aspect_2.registerPorts)(importations || [], exportations || []);
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ exports.initialize = void 0;
|
|||
var tslib_1 = require("tslib");
|
||||
var features_1 = require("./features");
|
||||
var actionDef_1 = require("oak-domain/lib/store/actionDef");
|
||||
var subscriber_1 = tslib_1.__importDefault(require("./utils/subscriber"));
|
||||
/**
|
||||
* @param storageSchema
|
||||
* @param createFeatures
|
||||
|
|
@ -23,6 +24,7 @@ function initialize(storageSchema, frontendContextBuilder, connector, checkers,
|
|||
var intCheckers = (0, actionDef_1.makeIntrinsicCTWs)(storageSchema, actionDict).checkers;
|
||||
var checkers2 = checkers.concat(intCheckers);
|
||||
var features1 = (0, features_1.initializeStep1)();
|
||||
var subscriber = new subscriber_1.default(connector.getSubscribeRouter());
|
||||
var wrapper = {
|
||||
exec: function (name, params) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
||||
var context, _a, result, opRecords, message;
|
||||
|
|
@ -41,6 +43,12 @@ function initialize(storageSchema, frontendContextBuilder, connector, checkers,
|
|||
}
|
||||
});
|
||||
}); },
|
||||
sub: function (data, callback) {
|
||||
return subscriber.sub(data, callback);
|
||||
},
|
||||
unsub: function (ids) {
|
||||
return subscriber.unsub(ids);
|
||||
},
|
||||
};
|
||||
var features2 = (0, features_1.initializeStep2)(features1, wrapper, storageSchema, frontendContextBuilder, checkers2, actionCascadePathGraph, relationCascadePathGraph, authDeduceRelationMap, colorDict, function () { return '请查看数据库中的数据'; }, function (url, headers) { return connector.makeBridgeUrl(url, headers); }, selectFreeEntities, createFreeEntities, updateFreeEntities, cacheSavedEntities, cacheKeepFreshPeriod);
|
||||
var features = Object.assign(features1, features2);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
import { io } from "socket.io-client";
|
||||
export default io;
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var socket_io_client_1 = require("socket.io-client");
|
||||
exports.default = socket_io_client_1.io;
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
"use strict";
|
||||
// 这里要处理小程序环境下的socketIO,待定
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
import { io } from "socket.io-client";
|
||||
export default io;
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var socket_io_client_1 = require("socket.io-client");
|
||||
exports.default = socket_io_client_1.io;
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
import { EntityDict, SubDataDef, OpRecord } from 'oak-domain/lib/types';
|
||||
import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain';
|
||||
export default class SubScriber<ED extends BaseEntityDict & EntityDict> {
|
||||
private getSubscribePointUrl;
|
||||
constructor(getSubscribePointUrl: string);
|
||||
sub(data: SubDataDef<ED, keyof ED>[], callback: (records: OpRecord<ED>[], ids: string[]) => void): Promise<void>;
|
||||
unsub(ids: string[]): Promise<void>;
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var tslib_1 = require("tslib");
|
||||
var SubScriber = /** @class */ (function () {
|
||||
function SubScriber(getSubscribePointUrl) {
|
||||
this.getSubscribePointUrl = getSubscribePointUrl;
|
||||
}
|
||||
SubScriber.prototype.sub = function (data, callback) {
|
||||
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
||||
return tslib_1.__generator(this, function (_a) {
|
||||
return [2 /*return*/];
|
||||
});
|
||||
});
|
||||
};
|
||||
SubScriber.prototype.unsub = function (ids) {
|
||||
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
||||
return tslib_1.__generator(this, function (_a) {
|
||||
return [2 /*return*/];
|
||||
});
|
||||
});
|
||||
};
|
||||
return SubScriber;
|
||||
}());
|
||||
exports.default = SubScriber;
|
||||
|
|
@ -29,14 +29,16 @@
|
|||
"ol": "^7.3.0",
|
||||
"react-scripts": "^5.0.1",
|
||||
"rmc-pull-to-refresh": "^1.0.13",
|
||||
"socket.io-client": "^4.7.2",
|
||||
"url": "^0.11.0",
|
||||
"uuid": "^8.3.2"
|
||||
"uuid": "^8.3.2",
|
||||
"weapp.socket.io": "^2.2.1"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0",
|
||||
"react-router-dom": "^6.3.0",
|
||||
"react-responsive": "^9.0.0-beta.10"
|
||||
"react-responsive": "^9.0.0-beta.10",
|
||||
"react-router-dom": "^6.3.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/cli": "^7.12.13",
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { EntityDict, OperateOption, SelectOption, OpRecord, AspectWrapper, CheckerType, Aspect, SelectOpResult, StorageSchema, Checker, EXPRESSION_PREFIX } from 'oak-domain/lib/types';
|
||||
import { EntityDict, OperateOption, SelectOption, OpRecord, AspectWrapper, CheckerType, Aspect, SelectOpResult, StorageSchema, Checker, SubDataDef } from 'oak-domain/lib/types';
|
||||
import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain';
|
||||
import { CommonAspectDict } from 'oak-common-aspect';
|
||||
import { Feature } from '../types/Feature';
|
||||
|
|
@ -19,6 +19,7 @@ interface CacheSelectOption extends SelectOption {
|
|||
ignoreKeepFreshRule?: true,
|
||||
};
|
||||
|
||||
|
||||
export class Cache<
|
||||
ED extends EntityDict & BaseEntityDict,
|
||||
Cxt extends AsyncContext<ED>,
|
||||
|
|
@ -641,4 +642,15 @@ export class Cache<
|
|||
buildContext() {
|
||||
return this.contextBuilder!();
|
||||
}
|
||||
|
||||
sub(data: Array<SubDataDef<ED, keyof ED>>, callback: (records: OpRecord<ED>[], ids: string[]) => void) {
|
||||
return this.aspectWrapper.sub(data, (records, ids) => {
|
||||
this.sync(records),
|
||||
callback(records, ids);
|
||||
});
|
||||
}
|
||||
|
||||
unsub(ids: string[]) {
|
||||
return this.aspectWrapper.unsub(ids);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import {
|
|||
Timer,
|
||||
} from 'oak-domain/lib/types';
|
||||
import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain';
|
||||
import { EntityDict } from 'oak-domain/lib/types/Entity';
|
||||
import { EntityDict, OpRecord, SubDataDef } from 'oak-domain/lib/types/Entity';
|
||||
import { makeIntrinsicCTWs } from 'oak-domain/lib/store/actionDef';
|
||||
|
||||
import { createDebugStore, clearMaterializedData } from './debugStore';
|
||||
|
|
@ -114,6 +114,18 @@ export function initialize<
|
|||
message: contextBackend.getMessage(),
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* dev模式下订阅数据没有意义(单用户模式)
|
||||
* @param data
|
||||
* @returns
|
||||
*/
|
||||
sub: function (data: SubDataDef<ED, keyof ED>[], callback: (records: OpRecord<ED>[], ids: string[]) => void): Promise<void> {
|
||||
return Promise.resolve();
|
||||
},
|
||||
unsub: function (ids: string[]): Promise<void> {
|
||||
return Promise.resolve();
|
||||
},
|
||||
};
|
||||
|
||||
const features2 = initBasicFeaturesStep2<ED, Cxt, FrontCxt, CommonAspectDict<ED, Cxt> & AD>(
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import {
|
|||
Connector,
|
||||
} from 'oak-domain/lib/types';
|
||||
import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain';
|
||||
import { EntityDict } from 'oak-domain/lib/types/Entity';
|
||||
import { EntityDict, OpRecord, SubDataDef } from 'oak-domain/lib/types/Entity';
|
||||
|
||||
import { initializeStep1 as initBasicFeaturesStep1, initializeStep2 as initBasicFeaturesStep2 } from './features';
|
||||
import { makeIntrinsicCTWs } from 'oak-domain/lib/store/actionDef';
|
||||
|
|
@ -16,6 +16,7 @@ import { AsyncContext } from 'oak-domain/lib/store/AsyncRowStore';
|
|||
import { SyncContext } from 'oak-domain/lib/store/SyncRowStore';
|
||||
import { InitializeOptions } from './types/Initialize';
|
||||
|
||||
import SubScriber from './utils/subscriber';
|
||||
/**
|
||||
* @param storageSchema
|
||||
* @param createFeatures
|
||||
|
|
@ -50,6 +51,7 @@ export function initialize<
|
|||
|
||||
const features1 = initBasicFeaturesStep1();
|
||||
|
||||
const subscriber = new SubScriber<ED>(connector.getSubscribeRouter());
|
||||
const wrapper: AspectWrapper<ED, Cxt, AD & CommonAspectDict<ED, Cxt>> = {
|
||||
exec: async (name, params) => {
|
||||
const context = features2.cache.buildContext();
|
||||
|
|
@ -60,6 +62,12 @@ export function initialize<
|
|||
message,
|
||||
};
|
||||
},
|
||||
sub: function (data: SubDataDef<ED, keyof ED>[], callback: (records: OpRecord<ED>[], ids: string[]) => void): Promise<void> {
|
||||
return subscriber.sub(data, callback);
|
||||
},
|
||||
unsub: function (ids: string[]): Promise<void> {
|
||||
return subscriber.unsub(ids);
|
||||
},
|
||||
};
|
||||
|
||||
const features2 = initBasicFeaturesStep2<ED, Cxt, FrontCxt, CommonAspectDict<ED, Cxt> & AD>(
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
// 这里要处理小程序环境下的socketIO,待定
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
import { io } from "socket.io-client";
|
||||
export default io;
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
import { io } from "socket.io-client";
|
||||
export default io;
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
import {
|
||||
Aspect,
|
||||
AspectWrapper,
|
||||
Checker,
|
||||
StorageSchema,
|
||||
Connector,
|
||||
EntityDict,
|
||||
SubDataDef,
|
||||
OpRecord,
|
||||
} from 'oak-domain/lib/types';
|
||||
import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain';
|
||||
|
||||
export default class SubScriber<ED extends BaseEntityDict & EntityDict>{
|
||||
private getSubscribePointUrl: string;
|
||||
constructor(getSubscribePointUrl: string) {
|
||||
this.getSubscribePointUrl = getSubscribePointUrl;
|
||||
}
|
||||
|
||||
async sub(data: SubDataDef<ED, keyof ED>[], callback: (records: OpRecord<ED>[], ids: string[]) => void) {
|
||||
}
|
||||
|
||||
async unsub(ids: string[]) {
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue