diff --git a/arkoala-arkts/.gitlab-ci.yml b/arkoala-arkts/.gitlab-ci.yml index 6adcdf502acabe7938d08c93ea446263e14e4aca..8b541459f98c83a27484fa3e3a0c15d8179edf13 100644 --- a/arkoala-arkts/.gitlab-ci.yml +++ b/arkoala-arkts/.gitlab-ci.yml @@ -272,7 +272,7 @@ install node modules (arkoala-arkts): - !reference [.setup, script] - npm run panda:sdk:install --prefix arkoala-arkts script: - - mkdir -p arkoala-arkts/build && cp arkoala-arkts/user/build/user.abc arkoala-arkts/build + - mkdir -p arkoala-arkts/build && cp arkoala-arkts/trivial/user/build/user.abc arkoala-arkts/build - npm run build:loader:node --prefix arkoala-arkts - npm run run:node:ci --prefix arkoala-arkts @@ -314,7 +314,7 @@ install node modules (arkoala-arkts): - npm run panda:sdk:install --prefix arkoala-arkts script: - npm run har-arm32 --prefix arkoala-arkts/trivial/user - - mv arkoala-arkts/user/app/user/build/default/outputs/default/user.har user-arm32.har + - mv arkoala-arkts/trivial/user/app/user/build/default/outputs/default/user.har user-arm32.har artifacts: paths: - user-arm32.har diff --git a/arkoala/arkui-common/src/arkts/Storage.ts b/arkoala/arkui-common/src/arkts/Storage.ts index 25290424194b795ab0b1d04cdcaf9d4d09b6ee52..3e2ece094cf6e09e0c09a91d3c1fad0ae1d4ba90 100644 --- a/arkoala/arkui-common/src/arkts/Storage.ts +++ b/arkoala/arkui-common/src/arkts/Storage.ts @@ -106,6 +106,14 @@ export class StorageMap { return StorageMap._shared as StorageMap } + constructor(initializer?: IterableIterator<[string, Object]>) { + if (initializer) { + for (const entry of initializer) { + this.create(entry[0], entry[1]) + } + } + } + keys(): IterableIterator { return this.map.keys() } @@ -165,7 +173,7 @@ export class StorageMap { return true } - private create(key: string, value: V, mutable?: boolean): StorageEntry { + create(key: string, value: V, mutable?: boolean): StorageEntry { const entry = new StorageEntry(this.manager.mutableState(value, true), mutable ?? true) this.map.set(key, entry) return entry @@ -173,7 +181,136 @@ export class StorageMap { } export class LocalStorage { - // todo + private static shared?: LocalStorage + /** @internal */ + readonly map: StorageMap + + /** + * Constructor. + * @since 9 + */ + constructor(initializingProperties?: IterableIterator<[string, Object]>) { + this.map = new StorageMap(initializingProperties) + } + + /** + * Get current LocalStorage shared from stage. + * @StageModelOnly + * @since 9 + * @deprecated since 10 + */ + static GetShared(): LocalStorage { + return LocalStorage.getShared() + } + /** + * Get current LocalStorage shared from stage. + * @StageModelOnly + * @since 10 + */ + static getShared(): LocalStorage { + if (!LocalStorage.shared) { + LocalStorage.shared = new LocalStorage() + } + return LocalStorage.shared as LocalStorage + } + + /** + * Return true if property with given name exists + * @since 9 + */ + has(propName: string): boolean { + return this.map.has(propName) + } + + /** + * Return a Map Iterator + * @since 9 + */ + keys(): IterableIterator { + return this.map.keys() + } + + /** + * Return number of properties + * @since 9 + */ + size(): number { + return this.map.size + } + + /** + * Return value of given property + * @since 9 + */ + get(propName: string): V | undefined { + return this.map.get(propName) + } + + /** + * Set value of given property + * @since 9 + */ + set(propName: string, newValue: V): boolean { + return this.map.set(propName, newValue, false) + } + + /** + * Add property if not property with given name + * @since 9 + */ + setOrCreate(propName: string, newValue: V): boolean { + this.map.set(propName, newValue, true) + return newValue != undefined + } + + /** + * Create and return a 'link' (two-way sync) to named property + * @since 9 + */ + link(propName: string): SubscribedAbstractProperty { + throw new Error("LocalStorage.link is not implemented") + } + + /** + * Like link(), will create and initialize a new source property in LocalStorge if missing + * @since 9 + */ + setAndLink(propName: string, defaultValue: V): SubscribedAbstractProperty { + throw new Error("LocalStorage.setAndLink is not implemented") + } + + /** + * Create and return a 'prop' (one-way sync) to named property + * @since 9 + */ + prop(propName: string): SubscribedAbstractProperty { + throw new Error("LocalStorage.prop is not implemented") + } + + /** + * Like prop(), will create and initialize a new source property in LocalStorage if missing + * @since 9 + */ + setAndProp(propName: string, defaultValue: S): SubscribedAbstractProperty { + throw new Error("LocalStorage.setAndProp is not implemented") + } + + /** + * Delete property from StorageBase + * @since 9 + * @returns false if method failed + */ + delete(propName: string): boolean { + return this.map.delete(propName) + } + + /** + * Delete all properties from the StorageBase + * @since 9 + */ + clear(): boolean { + return this.map.clear() + } } /**