Merge branch 'dev' of codeup.aliyun.com:61c14a7efa282c88e103c23f/oak-frontend-base into dev

This commit is contained in:
Xu Chang 2022-06-21 10:40:03 +08:00
commit ee44b1743a
17 changed files with 175 additions and 84 deletions

View File

@ -24,6 +24,6 @@ export declare class DebugStore<ED extends EntityDict, Cxt extends Context<ED>>
registerTrigger<T extends keyof ED>(trigger: Trigger<ED, T, Cxt>): void;
registerChecker<T extends keyof ED>(checker: Checker<ED, T, Cxt>): void;
startInitializing(): void;
endInitalizing(): void;
endInitializing(): void;
}
export {};

View File

@ -85,7 +85,7 @@ class DebugStore extends oak_memory_tree_store_1.TreeStore {
startInitializing() {
this.rwLock.acquire('X');
}
endInitalizing() {
endInitializing() {
this.rwLock.release();
}
}

View File

@ -22,10 +22,10 @@ async function initDataInStore(store, createContext, initialData) {
}
await context.commit();
}
store.endInitalizing();
store.endInitializing();
}
function getMaterializedData() {
if ( /* process.env.OAK_PLATFORM === 'weChatMp' */true) {
if (process.env.OAK_PLATFORM === 'weChatMp') {
try {
const data = wx.getStorageSync('debugStore');
const stat = wx.getStorageSync('debugStoreStat');
@ -41,10 +41,26 @@ function getMaterializedData() {
return;
}
}
else if (process.env.OAK_PLATFORM === 'web') {
try {
const data = JSON.parse(window.localStorage.getItem('debugStore'));
const stat = JSON.parse(window.localStorage.getItem('debugStoreStat'));
if (data && stat) {
return {
data,
stat,
};
}
return;
}
catch (e) {
return;
}
}
}
let lastMaterializedVersion = 0;
function materializeData(data, stat) {
if ( /* process.env.OAK_PLATFORM === 'weChatMp' */true) {
if (process.env.OAK_PLATFORM === 'weChatMp') {
try {
wx.setStorageSync('debugStore', data);
wx.setStorageSync('debugStoreStat', stat);
@ -62,6 +78,18 @@ function materializeData(data, stat) {
});
}
}
else if (process.env.OAK_PLATFORM === 'web') {
try {
window.localStorage.setItem('debugStore', typeof data === 'string' ? data : JSON.stringify(data));
window.localStorage.setItem('debugStoreStat', JSON.stringify(stat));
lastMaterializedVersion = stat.commit;
alert('数据已物化');
}
catch (e) {
console.error(e);
alert('物化数据失败');
}
}
}
/**
* 在debug环境上创建watcher

View File

@ -25,9 +25,3 @@ __exportStar(require("./types/Feature"), exports);
__exportStar(require("./types/ExceptionRoute"), exports);
__exportStar(require("./features/cache"), exports);
__exportStar(require("./features/upload"), exports);
/* export {
initI18nWechatMp,
getI18nInstanceWechatMp,
I18nWechatMpRuntimeBase,
I18nWechatMp,
} from './platforms/wechatMp/i18n'; */

View File

@ -37,16 +37,16 @@ function createAspectProxy(storageSchema, createContext, triggers, checkers, wat
return async (params, scene) => {
const runningContext = createContext(debugStore, scene);
await runningContext.begin();
let aspectCompeleted = false;
let aspectCompleted = false;
try {
const result = await aspect(params, runningContext);
await runningContext.commit();
aspectCompeleted = true;
aspectCompleted = true;
await features.cache.sync(runningContext.opRecords);
return result;
}
catch (err) {
if (!aspectCompeleted) {
if (!aspectCompleted) {
await runningContext.rollback();
}
if (err instanceof types_1.OakRowInconsistencyException) {

View File

@ -25,6 +25,11 @@ export declare class I18nWechatMpRuntimeBase implements CommonI18nInterface {
t(key: string, options?: object): string;
getFallbackLocale(): string;
}
declare global {
const OakI18n: {
i18nInstance: I18nWechatMpRuntimeBase | null;
};
}
export declare function initI18nWechatMp(options: {
locales: Locales;
defaultLocale?: string;

View File

@ -12,7 +12,7 @@ class I18nWechatMpRuntimeBase {
translations;
currentLocale;
fallbackLocale;
constructor(translations = {}, currentLocale = "zh_CN" /* Locale.default */, fallbackLocale = "zh_CN" /* Locale.default */) {
constructor(translations = {}, currentLocale = "zh_CN" /* default */, fallbackLocale = "zh_CN" /* default */) {
this.translations = translations;
this.currentLocale = currentLocale;
this.fallbackLocale = fallbackLocale;

View File

@ -1,10 +1,4 @@
/// <reference types="wechat-miniprogram" />
/// <reference types="wechat-miniprogram" />
/// <reference types="wechat-miniprogram" />
/// <reference types="wechat-miniprogram" />
/// <reference types="wechat-miniprogram" />
/// <reference types="wechat-miniprogram" />
/// <reference types="wechat-miniprogram" />
import './polyfill';
import { Aspect, Checker, Context, EntityDict, RowStore, StorageSchema, Trigger, ActionDictOfEntityDict, DeduceSorterItem, DeduceOperation, SelectRowShape, Watcher } from "oak-domain/lib/types";
import { Feature } from '../../types/Feature';
@ -13,6 +7,8 @@ import { BasicFeatures } from "../../features";
import { ExceptionRouters } from '../../types/ExceptionRoute';
import { NamedFilterItem, NamedSorterItem } from '../../types/NamedCondition';
import { CreateNodeOptions } from '../../features/runningTree';
import { initI18nWechatMp, I18nWechatMpRuntimeBase, getI18nInstanceWechatMp } from './i18n/index';
export { initI18nWechatMp, getI18nInstanceWechatMp, I18nWechatMpRuntimeBase, };
declare type RowSelected<ED extends EntityDict, T extends keyof ED, Proj extends ED[T]['Selection']['data'] = Required<ED[T]['Selection']['data']>> = SelectRowShape<ED[T]['Schema'], Proj> | undefined;
declare type OakComponentOption<ED extends EntityDict, T extends keyof ED, Cxt extends Context<ED>, AD extends Record<string, Aspect<ED, Cxt>>, FD extends Record<string, Feature<ED, Cxt, AD>>, FormedData extends WechatMiniprogram.Component.DataOption, IsList extends boolean> = {
entity: T;
@ -159,4 +155,3 @@ export declare function initialize<ED extends EntityDict, Cxt extends Context<ED
declare type OakWechatMpOptions<TData extends WechatMiniprogram.Component.DataOption, TProperty extends WechatMiniprogram.Component.PropertyOption, TMethod extends WechatMiniprogram.Component.MethodOption, InherentProperties extends WechatMiniprogram.Component.PropertyOption, InherentMethods extends WechatMiniprogram.Component.MethodOption, InherentData extends WechatMiniprogram.Component.DataOption, InherentInstanceProperty extends WechatMiniprogram.IAnyObject, TCustomInstanceProperty extends WechatMiniprogram.IAnyObject = {}, TIsPage extends boolean = false> = Partial<TData> & Partial<WechatMiniprogram.Component.Property<TProperty>> & Partial<WechatMiniprogram.Component.Method<TMethod, TIsPage>> & Partial<WechatMiniprogram.Component.OtherOption> & Partial<WechatMiniprogram.Component.Lifetimes> & ThisType<WechatMiniprogram.Component.Instance<TData & InherentData, TProperty & InherentProperties, TMethod & InherentMethods, TCustomInstanceProperty & InherentInstanceProperty, TIsPage>>;
export declare type MakeOakPage<ED extends EntityDict, Cxt extends Context<ED>, AD extends Record<string, Aspect<ED, Cxt>>, FD extends Record<string, Feature<ED, Cxt, AD>>> = <T extends keyof ED, D extends WechatMiniprogram.Component.DataOption, P extends WechatMiniprogram.Component.PropertyOption, M extends WechatMiniprogram.Component.MethodOption, Proj extends ED[T]['Selection']['data'], IsList extends boolean, IS extends WechatMiniprogram.IAnyObject = {}, FormedData extends WechatMiniprogram.Component.DataOption = {}>(options: OakPageOption<ED, T, Cxt, AD, FD, Proj, FormedData, IsList> & ThisType<WechatMiniprogram.Component.Instance<D & OakPageData, P & OakPageProperties, M & OakPageMethods<ED, T>, IS & OakPageInstanceProperties<ED, Cxt, AD, FD>, true>>, componentOptions: OakWechatMpOptions<D, P, M, OakPageProperties, OakPageMethods<ED, T>, OakPageData & FormedData, OakPageInstanceProperties<ED, Cxt, AD, FD>, IS, true>) => string;
export declare type MakeOakComponent<ED extends EntityDict, Cxt extends Context<ED>, AD extends Record<string, Aspect<ED, Cxt>>, FD extends Record<string, Feature<ED, Cxt, AD>>> = <T extends keyof ED, D extends WechatMiniprogram.Component.DataOption, P extends WechatMiniprogram.Component.PropertyOption, M extends WechatMiniprogram.Component.MethodOption, IsList extends boolean, IS extends WechatMiniprogram.IAnyObject = {}, FormedData extends WechatMiniprogram.Component.DataOption = {}>(options: OakComponentOption<ED, T, Cxt, AD, FD, FormedData, IsList> & ThisType<WechatMiniprogram.Component.Instance<D & OakPageData, P & OakPageProperties, M & OakPageMethods<ED, T>, IS & OakPageInstanceProperties<ED, Cxt, AD, FD>, true>>, componentOptions: OakWechatMpOptions<D, P, M, OakComponentProperties, OakComponentMethods<ED, T>, OakComponentData & FormedData, OakComponentInstanceProperties<ED, Cxt, AD, FD>, IS, false>) => string;
export {};

View File

@ -3,13 +3,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.initialize = void 0;
exports.initialize = exports.I18nWechatMpRuntimeBase = exports.getI18nInstanceWechatMp = exports.initI18nWechatMp = void 0;
require("./polyfill");
const types_1 = require("oak-domain/lib/types");
const initialize_1 = require("../../initialize");
const assert_1 = __importDefault(require("assert"));
const lodash_1 = require("lodash");
const index_1 = require("./i18n/index");
Object.defineProperty(exports, "initI18nWechatMp", { enumerable: true, get: function () { return index_1.initI18nWechatMp; } });
Object.defineProperty(exports, "I18nWechatMpRuntimeBase", { enumerable: true, get: function () { return index_1.I18nWechatMpRuntimeBase; } });
Object.defineProperty(exports, "getI18nInstanceWechatMp", { enumerable: true, get: function () { return index_1.getI18nInstanceWechatMp; } });
;
function callPicker(features, attr, params, entity, parent) {
const relation = features.cache.judgeRelation(entity, attr);
@ -479,11 +482,15 @@ function createPageOptions(options, doSubscribe, features, exceptionRouterDict)
oakEntity: node.getEntity(),
oakFullpath: path2,
oakFrom,
newOakActions: oakActions && JSON.parse(oakActions).length > 0 ? JSON.parse(oakActions) : options.actions || [],
newOakActions: oakActions && JSON.parse(oakActions).length > 0
? JSON.parse(oakActions)
: options.actions || [],
}, () => {
this.isReady = true;
if (this.isReady) {
this.refresh();
}
});
if (this.isReady) {
this.refresh();
}
},
...makeComponentMethods(features, doSubscribe, formData, exceptionRouterDict),
},
@ -524,7 +531,7 @@ function createPageOptions(options, doSubscribe, features, exceptionRouterDict)
};
return componentOptions;
}
function createComponentOptions(options, features, doSubscribe, exceptionRouterDict) {
function createComponentOptions(options, doSubscribe, features, exceptionRouterDict) {
const { formData, entity } = options;
const componentOptions = {
properties: {
@ -533,21 +540,25 @@ function createComponentOptions(options, features, doSubscribe, exceptionRouterD
oakParent: String,
},
observers: {
"oakPath": function (path) {
oakPath: function (path) {
return this.onPropsChanged({
path,
});
},
"oakParent": function (parent) {
oakParent: function (parent) {
return this.onPropsChanged({
parent,
});
}
},
},
methods: {
async onPropsChanged(options) {
const path2 = options.hasOwnProperty('path') ? options.path : this.data.oakPath;
const parent2 = options.hasOwnProperty('parent') ? options.parent : this.data.oakParent;
const path2 = options.hasOwnProperty('path')
? options.path
: this.data.oakPath;
const parent2 = options.hasOwnProperty('parent')
? options.parent
: this.data.oakParent;
if (path2 && parent2) {
const oakFullpath2 = `${parent2}.${path2}`;
if (oakFullpath2 !== this.data.oakFullpath) {
@ -559,7 +570,7 @@ function createComponentOptions(options, features, doSubscribe, exceptionRouterD
}
}
},
...makeComponentMethods(features, doSubscribe, formData, exceptionRouterDict)
...makeComponentMethods(features, doSubscribe, formData, exceptionRouterDict),
},
lifetimes: {
async created() {
@ -598,7 +609,7 @@ function createComponentOptions(options, features, doSubscribe, exceptionRouterD
},
hide() {
this.unsubscribe();
}
},
},
};
return componentOptions;
@ -724,7 +735,7 @@ function initialize(storageSchema, createFeatures, createContext, exceptionRoute
});
},
OakComponent: (options, componentOptions = {}) => {
const oakOptions = createComponentOptions(options, features, subscribe, exceptionRouterDict);
const oakOptions = createComponentOptions(options, subscribe, features, exceptionRouterDict);
const { properties, pageLifetimes, lifetimes, methods, data, observers } = oakOptions;
const { properties: p2, pageLifetimes: pl2, lifetimes: l2, methods: m2, data: d2, observers: o2, ...restOptions } = componentOptions;
const pls = [pageLifetimes, pl2].filter(ele => !!ele);

View File

@ -113,7 +113,7 @@ export class DebugStore<ED extends EntityDict, Cxt extends Context<ED>> extends
this.rwLock.acquire('X');
}
endInitalizing() {
endInitializing() {
this.rwLock.release();
}
}

View File

@ -26,11 +26,11 @@ async function initDataInStore<ED extends EntityDict, Cxt extends Context<ED>>(
}
await context.commit();
}
store.endInitalizing();
store.endInitializing();
}
function getMaterializedData() {
if (/* process.env.OAK_PLATFORM === 'weChatMp' */true) {
if (process.env.OAK_PLATFORM === 'weChatMp') {
try {
const data = wx.getStorageSync('debugStore');
const stat = wx.getStorageSync('debugStoreStat');
@ -46,12 +46,31 @@ function getMaterializedData() {
return;
}
}
else if (process.env.OAK_PLATFORM === 'web') {
try {
const data = JSON.parse(
window.localStorage.getItem('debugStore') as string
);
const stat = JSON.parse(
window.localStorage.getItem('debugStoreStat') as string
);
if (data && stat) {
return {
data,
stat,
};
}
return;
} catch (e) {
return;
}
}
}
let lastMaterializedVersion = 0;
function materializeData(data: any, stat: { create: number, update: number, remove: number, commit: number }) {
if (/* process.env.OAK_PLATFORM === 'weChatMp' */true) {
if (process.env.OAK_PLATFORM === 'weChatMp') {
try {
wx.setStorageSync('debugStore', data);
wx.setStorageSync('debugStoreStat', stat);
@ -69,6 +88,17 @@ function materializeData(data: any, stat: { create: number, update: number, remo
});
}
}
else if (process.env.OAK_PLATFORM === 'web') {
try {
window.localStorage.setItem('debugStore', typeof data === 'string' ? data : JSON.stringify(data));
window.localStorage.setItem('debugStoreStat', JSON.stringify(stat));
lastMaterializedVersion = stat.commit;
alert('数据已物化');
} catch (e) {
console.error(e);
alert('物化数据失败');
}
}
}
/**

View File

@ -11,9 +11,4 @@ export * from './types/ExceptionRoute';
export { BasicFeatures } from './features';
export * from './features/cache';
export * from './features/upload';
/* export {
initI18nWechatMp,
getI18nInstanceWechatMp,
I18nWechatMpRuntimeBase,
I18nWechatMp,
} from './platforms/wechatMp/i18n'; */

View File

@ -36,18 +36,18 @@ function createAspectProxy<ED extends EntityDict, Cxt extends Context<ED>,
return async (params: Parameters<typeof aspect>[0], scene: string) => {
const runningContext = createContext(debugStore, scene);
await runningContext.begin();
let aspectCompeleted = false;
let aspectCompleted = false;
try {
const result = await aspect(params, runningContext);
await runningContext.commit();
aspectCompeleted = true;
aspectCompleted = true;
await features.cache.sync(runningContext.opRecords);
return result;
}
catch(err) {
if (!aspectCompeleted) {
await runningContext.rollback();
if (!aspectCompleted) {
await runningContext.rollback();
}
if (err instanceof OakRowInconsistencyException) {
// 在这里可以同步相应的数据 todo

View File

@ -91,6 +91,12 @@ export class I18nWechatMpRuntimeBase implements CommonI18nInterface {
}
}
declare global {
const OakI18n: {
i18nInstance: I18nWechatMpRuntimeBase | null;
};
}
export function initI18nWechatMp(options: {
locales: Locales;
defaultLocale?: string;

View File

@ -9,7 +9,19 @@ import { assign, union } from "lodash";
import { ExceptionHandler, ExceptionRouters } from '../../types/ExceptionRoute';
import { NamedFilterItem, NamedSorterItem } from '../../types/NamedCondition';
import { CreateNodeOptions } from '../../features/runningTree';
import { getI18nInstanceWechatMp, CURRENT_LOCALE_KEY, CURRENT_LOCALE_DATA } from './i18n/index';
import {
initI18nWechatMp,
I18nWechatMpRuntimeBase,
getI18nInstanceWechatMp,
CURRENT_LOCALE_KEY,
CURRENT_LOCALE_DATA,
} from './i18n/index';
export {
initI18nWechatMp,
getI18nInstanceWechatMp,
I18nWechatMpRuntimeBase,
};
type RowSelected<
ED extends EntityDict,
@ -750,15 +762,23 @@ function createPageOptions<ED extends EntityDict,
id: oakId,
});
// const oakFullpath = oakParent ? `${oakParent}.${oakPath || options.path}` : oakPath || options.path;
this.setData({
oakEntity: node.getEntity(),
oakFullpath: path2,
oakFrom,
newOakActions: oakActions && JSON.parse(oakActions).length > 0 ? JSON.parse(oakActions) : options.actions || [],
});
if (this.isReady) {
this.refresh();
}
this.setData(
{
oakEntity: node.getEntity(),
oakFullpath: path2,
oakFrom,
newOakActions:
oakActions && JSON.parse(oakActions).length > 0
? JSON.parse(oakActions)
: options.actions || [],
},
() => {
this.isReady = true;
if (this.isReady) {
this.refresh();
}
}
);
},
...makeComponentMethods(features, doSubscribe, formData as any, exceptionRouterDict),
@ -808,17 +828,20 @@ function createPageOptions<ED extends EntityDict,
}
function createComponentOptions<ED extends EntityDict,
function createComponentOptions<
ED extends EntityDict,
T extends keyof ED,
Cxt extends Context<ED>,
AD extends Record<string, Aspect<ED, Cxt>>,
FD extends Record<string, Feature<ED, Cxt, AD>>,
IsList extends boolean,
FormedData extends WechatMiniprogram.Component.DataOption>(
options: OakComponentOption<ED, T, Cxt, AD, FD, FormedData, IsList>,
features: BasicFeatures<ED, Cxt, AD> & FD,
doSubscribe: ReturnType<typeof init>['subscribe'],
exceptionRouterDict: Record<string, ExceptionHandler>) {
FormedData extends WechatMiniprogram.Component.DataOption
>(
options: OakComponentOption<ED, T, Cxt, AD, FD, FormedData, IsList>,
doSubscribe: ReturnType<typeof init>['subscribe'],
features: BasicFeatures<ED, Cxt, AD> & FD,
exceptionRouterDict: Record<string, ExceptionHandler>
) {
const { formData, entity } = options;
const componentOptions: WechatMiniprogram.Component.Options<
@ -833,21 +856,25 @@ function createComponentOptions<ED extends EntityDict,
oakParent: String,
},
observers: {
"oakPath": function (path) {
oakPath: function (path) {
return this.onPropsChanged({
path,
})
});
},
"oakParent": function (parent) {
oakParent: function (parent) {
return this.onPropsChanged({
parent,
})
}
});
},
},
methods: {
async onPropsChanged(options) {
const path2 = options.hasOwnProperty('path') ? options.path! : this.data.oakPath;
const parent2 = options.hasOwnProperty('parent') ? options.parent! : this.data.oakParent;
const path2 = options.hasOwnProperty('path')
? options.path!
: this.data.oakPath;
const parent2 = options.hasOwnProperty('parent')
? options.parent!
: this.data.oakParent;
if (path2 && parent2) {
const oakFullpath2 = `${parent2}.${path2}`;
if (oakFullpath2 !== this.data.oakFullpath) {
@ -859,7 +886,12 @@ function createComponentOptions<ED extends EntityDict,
}
}
},
...makeComponentMethods(features, doSubscribe, formData, exceptionRouterDict)
...makeComponentMethods(
features,
doSubscribe,
formData,
exceptionRouterDict
),
},
lifetimes: {
@ -890,7 +922,6 @@ function createComponentOptions<ED extends EntityDict,
}
},
async detached() {
this.unsubscribe();
// await context.rollback();
@ -904,7 +935,7 @@ function createComponentOptions<ED extends EntityDict,
},
hide() {
this.unsubscribe();
}
},
},
};
@ -1088,7 +1119,7 @@ export function initialize<ED extends EntityDict, Cxt extends Context<ED>, AD ex
IS,
true
> = {}) => {
const oakOptions = createComponentOptions(options, features, subscribe, exceptionRouterDict);
const oakOptions = createComponentOptions(options, subscribe, features, exceptionRouterDict);
const { properties, pageLifetimes, lifetimes, methods, data, observers } = oakOptions;
const { properties: p2, pageLifetimes: pl2, lifetimes: l2, methods: m2, data: d2, observers: o2, ...restOptions } = componentOptions;

View File

@ -1,11 +1,5 @@
import { I18nWechatMpRuntimeBase } from '../platforms/wechatMp/i18n';
declare global {
const generateNewId: (options?: { timestamp?: boolean }) => Promise<string>;
const OakI18n: {
i18nInstance: I18nWechatMpRuntimeBase | null;
} = {
i18nInstance: null,
};
}
export {};

View File

@ -70,7 +70,9 @@
"node",
"miniprogram-api-typings"
],
"include": [ "src/**/*.ts" ],
"include": [
"src/**/*.ts",
],
"exclude": [
"node_modules",
"**/*.spec.ts",