h5:add storage plugin

This commit is contained in:
pengfei.zhou 2019-12-25 15:19:41 +08:00 committed by osborn
parent 76e15e17ee
commit 48e6066e75
6 changed files with 95 additions and 20 deletions

View File

@ -2062,7 +2062,7 @@ class LayoutConfigImpl {
this.margin = m; this.margin = m;
return this; return this;
} }
configAligmnet(a) { configAlignmnet(a) {
this.alignment = a; this.alignment = a;
return this; return this;
} }
@ -2239,29 +2239,26 @@ class Panel {
}, undefined); }, undefined);
} }
nativeRender(model) { nativeRender(model) {
if (this.context) {
this.context.shader.render(model); this.context.shader.render(model);
} }
}
hookBeforeNativeCall() { hookBeforeNativeCall() {
this.__root__.clean();
for (let v of this.headviews.values()) {
v.clean();
}
} }
hookAfterNativeCall() { hookAfterNativeCall() {
//Here insert a native call to ensure the promise is resolved done. //Here insert a native call to ensure the promise is resolved done.
nativeEmpty(); Promise.resolve().then(() => {
if (this.__root__.isDirty()) { if (this.__root__.isDirty()) {
const model = this.__root__.toModel(); const model = this.__root__.toModel();
this.nativeRender(model); this.nativeRender(model);
this.__root__.clean();
} }
for (let v of this.headviews.values()) { for (let v of this.headviews.values()) {
if (v.isDirty()) { if (v.isDirty()) {
const model = v.toModel(); const model = v.toModel();
this.nativeRender(model); this.nativeRender(model);
v.clean();
} }
} }
});
} }
} }
__decorate$2([ __decorate$2([
@ -4455,6 +4452,33 @@ return __module.exports;
} }
} }
class StoragePlugin extends DoricPlugin {
setItem(args) {
localStorage.setItem(`${args.zone}_${args.key}`, args.value);
return Promise.resolve();
}
getItem(args) {
return Promise.resolve(localStorage.getItem(`${args.zone}_${args.key}`));
}
remove(args) {
localStorage.removeItem(`${args.zone}_${args.key}`);
return Promise.resolve();
}
clear(args) {
let removingKeys = [];
for (let i = 0; i < localStorage.length; i++) {
const key = localStorage.key(i);
if (key && key.startsWith(`${args.zone}_`)) {
removingKeys.push(key);
}
}
removingKeys.forEach(e => {
localStorage.removeItem(e);
});
return Promise.resolve();
}
}
const bundles = new Map; const bundles = new Map;
const plugins = new Map; const plugins = new Map;
const nodes = new Map; const nodes = new Map;
@ -4475,6 +4499,7 @@ return __module.exports;
} }
registerPlugin('shader', ShaderPlugin); registerPlugin('shader', ShaderPlugin);
registerPlugin('modal', ModalPlugin); registerPlugin('modal', ModalPlugin);
registerPlugin('storage', StoragePlugin);
registerViewNode('Stack', DoricStackNode); registerViewNode('Stack', DoricStackNode);
registerViewNode('VLayout', DoricVLayoutNode); registerViewNode('VLayout', DoricVLayoutNode);
registerViewNode('HLayout', DoricHLayoutNode); registerViewNode('HLayout', DoricHLayoutNode);
@ -4513,6 +4538,9 @@ ${content}
},doric.jsObtainContext("${contextId}"),[undefined,doric.jsObtainContext("${contextId}"),doric.jsObtainEntry("${contextId}"),doric.__require__,{},doricSetTimeout,doricSetInterval,doricClearTimeout,doricClearInterval])`; },doric.jsObtainContext("${contextId}"),[undefined,doric.jsObtainContext("${contextId}"),doric.jsObtainEntry("${contextId}"),doric.__require__,{},doricSetTimeout,doricSetInterval,doricClearTimeout,doricClearInterval])`;
} }
function initDoric() { function initDoric() {
injectGlobalObject("Environment", {
platform: "h5"
});
injectGlobalObject("nativeEmpty", () => undefined); injectGlobalObject("nativeEmpty", () => undefined);
injectGlobalObject('nativeLog', (type, message) => { injectGlobalObject('nativeLog', (type, message) => {
switch (type) { switch (type) {

File diff suppressed because one or more lines are too long

View File

@ -15,7 +15,7 @@
continue.</strong> continue.</strong>
</noscript> </noscript>
<div id="app"> <div id="app">
<doric-div src="../doric-demo/bundle/src/Counter.js" alias="test"> <doric-div src="../doric-demo/bundle/src/StorageDemo.js" alias="test">
</doric-div> </doric-div>
</div> </div>
<script type="text/javascript" src="./dist/index.js"></script> <script type="text/javascript" src="./dist/index.js"></script>

View File

@ -1,4 +1,4 @@
import { jsCallResolve, jsCallReject, jsCallbackTimer } from 'doric/src/runtime/sandbox' import { jsCallResolve, jsCallReject, jsCallbackTimer, jsCallEntityMethod } from 'doric/src/runtime/sandbox'
import { acquireJSBundle, acquirePlugin } from './DoricRegistry' import { acquireJSBundle, acquirePlugin } from './DoricRegistry'
import { getDoricContext } from './DoricContext' import { getDoricContext } from './DoricContext'
import { DoricPlugin } from './DoricPlugin' import { DoricPlugin } from './DoricPlugin'
@ -41,6 +41,10 @@ ${content}
} }
function initDoric() { function initDoric() {
injectGlobalObject("Environment", {
platform: "h5"
})
injectGlobalObject("nativeEmpty", () => undefined) injectGlobalObject("nativeEmpty", () => undefined)
injectGlobalObject('nativeLog', (type: 'd' | 'w' | 'e', message: string) => { injectGlobalObject('nativeLog', (type: 'd' | 'w' | 'e', message: string) => {

View File

@ -8,6 +8,7 @@ import { DoricTextNode } from "./shader/DoricTextNode"
import { DoricImageNode } from "./shader/DoricImageNode" import { DoricImageNode } from "./shader/DoricImageNode"
import { DoricScrollerNode } from "./shader/DoricScrollerNode" import { DoricScrollerNode } from "./shader/DoricScrollerNode"
import { ModalPlugin } from './plugins/ModalPlugin' import { ModalPlugin } from './plugins/ModalPlugin'
import { StoragePlugin } from "./plugins/StoragePlugin"
const bundles: Map<string, string> = new Map const bundles: Map<string, string> = new Map
@ -42,6 +43,7 @@ export function acquireViewNode(name: string) {
registerPlugin('shader', ShaderPlugin) registerPlugin('shader', ShaderPlugin)
registerPlugin('modal', ModalPlugin) registerPlugin('modal', ModalPlugin)
registerPlugin('storage', StoragePlugin)
registerViewNode('Stack', DoricStackNode) registerViewNode('Stack', DoricStackNode)
registerViewNode('VLayout', DoricVLayoutNode) registerViewNode('VLayout', DoricVLayoutNode)

View File

@ -0,0 +1,41 @@
import { DoricPlugin } from "../DoricPlugin";
export class StoragePlugin extends DoricPlugin {
setItem(args: {
zone?: string,
key: string,
value: string
}) {
localStorage.setItem(`${args.zone}_${args.key}`, args.value)
return Promise.resolve()
}
getItem(args: {
zone?: string,
key: string,
}) {
return Promise.resolve(localStorage.getItem(`${args.zone}_${args.key}`))
}
remove(args: {
zone?: string,
key: string,
}) {
localStorage.removeItem(`${args.zone}_${args.key}`)
return Promise.resolve()
}
clear(args: {
zone: string,
}) {
let removingKeys = []
for (let i = 0; i < localStorage.length; i++) {
const key = localStorage.key(i)
if (key && key.startsWith(`${args.zone}_`)) {
removingKeys.push(key)
}
}
removingKeys.forEach(e => {
localStorage.removeItem(e)
})
return Promise.resolve()
}
}