h5:add storage plugin
This commit is contained in:
@@ -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 { getDoricContext } from './DoricContext'
|
||||
import { DoricPlugin } from './DoricPlugin'
|
||||
@@ -41,6 +41,10 @@ ${content}
|
||||
}
|
||||
|
||||
function initDoric() {
|
||||
injectGlobalObject("Environment", {
|
||||
platform: "h5"
|
||||
})
|
||||
|
||||
injectGlobalObject("nativeEmpty", () => undefined)
|
||||
|
||||
injectGlobalObject('nativeLog', (type: 'd' | 'w' | 'e', message: string) => {
|
||||
|
@@ -8,6 +8,7 @@ import { DoricTextNode } from "./shader/DoricTextNode"
|
||||
import { DoricImageNode } from "./shader/DoricImageNode"
|
||||
import { DoricScrollerNode } from "./shader/DoricScrollerNode"
|
||||
import { ModalPlugin } from './plugins/ModalPlugin'
|
||||
import { StoragePlugin } from "./plugins/StoragePlugin"
|
||||
|
||||
const bundles: Map<string, string> = new Map
|
||||
|
||||
@@ -42,6 +43,7 @@ export function acquireViewNode(name: string) {
|
||||
|
||||
registerPlugin('shader', ShaderPlugin)
|
||||
registerPlugin('modal', ModalPlugin)
|
||||
registerPlugin('storage', StoragePlugin)
|
||||
|
||||
registerViewNode('Stack', DoricStackNode)
|
||||
registerViewNode('VLayout', DoricVLayoutNode)
|
||||
|
41
doric-h5/src/plugins/StoragePlugin.ts
Normal file
41
doric-h5/src/plugins/StoragePlugin.ts
Normal 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()
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user