diff --git a/frameworks/bridge/declarative_frontend/engine/stateMgmt.js b/frameworks/bridge/declarative_frontend/engine/stateMgmt.js index e9f565c92f5e2890f1495914cdd6d91f200e2ef4..2daa49f7e3c8cf7ab11e9b0016fbaa94179d7690 100644 --- a/frameworks/bridge/declarative_frontend/engine/stateMgmt.js +++ b/frameworks/bridge/declarative_frontend/engine/stateMgmt.js @@ -447,7 +447,7 @@ class LocalStorage extends NativeLocalStorage { } } /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -472,26 +472,26 @@ class LocalStorage extends NativeLocalStorage { */ class AppStorage extends LocalStorage { /** singleton class, app can not create instances - * - * not a public / sdk function + * + * not a public / sdk function */ constructor(initializingProperties) { super(initializingProperties); } /** - * create and initialize singleton - * initialzie with all properties and their values that Object.keys(params) returns - * Property values must not be undefined. - * - * not a public / sdk function - */ - static CreateSingleton(initializingPropersties) { - if (!AppStorage.Instance_) { + * create and initialize singleton + * initialzie with all properties and their values that Object.keys(params) returns + * Property values must not be undefined. + * + * not a public / sdk function + */ + static createSingleton(initializingPropersties) { + if (!AppStorage.instance_) { - AppStorage.Instance_ = new AppStorage(initializingPropersties); + AppStorage.instance_ = new AppStorage(initializingPropersties); } else { - stateMgmtConsole.error("AppStorage.CreateNewInstance(..): instance exists already, internal error!"); + stateMgmtConsole.error("AppStorage.createNewInstance(..): instance exists already, internal error!"); } } /** @@ -500,20 +500,28 @@ class AppStorage extends LocalStorage { * Same as @see LocalStorage.link() * * @param propName name of source property in AppStorage - * @param linkUser IPropertySubscriber to be notified when source changes, - * @param subscribersName the linkUser (subscriber) uses this name for the property - * this name will be used in propertyChange(propName) callback of IMultiPropertiesChangeSubscriber - * @returns SynchedPropertyTwoWay{Simple|Object| object with given LocalStoage prop as its source. - * Apps can use SDK functions of base class SubscribedAbstractProperty - * return undefiend if named property does not already exist in AppStorage - * - * @since 7 - */ + * @param linkUser IPropertySubscriber to be notified when source changes, + * @param subscribersName the linkUser (subscriber) uses this name for the property + * this name will be used in propertyChange(propName) callback of IMultiPropertiesChangeSubscriber + * @returns SynchedPropertyTwoWay{Simple|Object| object with given LocalStoage prop as its source. + * Apps can use SDK functions of base class SubscribedAbstractProperty + * return undefiend if named property does not already exist in AppStorage + * + * @since 9 + */ + static link(key, linkUser, subscribersName) { + return AppStorage.getOrCreate().link(key, linkUser, subscribersName); + } + /** + * @see link + * @since 7 + * @deprecated + */ static Link(key, linkUser, subscribersName) { - return AppStorage.GetOrCreate().link(key, linkUser, subscribersName); + return AppStorage.getOrCreate().link(key, linkUser, subscribersName); } /** - * Like @see link(), but will create and initialize a new source property in LocalStorge if missing + * Like @see link(), but will create and initialize a new source property in LocalStorage if missing * * Same as @see LocalStorage.setAndLink() * @@ -526,79 +534,121 @@ class AppStorage extends LocalStorage { * @returns SynchedPropertyTwoWay{Simple|Object| object with given LocalStoage prop as its source. * Apps can use SDK functions of base class SubscribedAbstractProperty * + * @since 9 + */ + static setAndLink(key, defaultValue, linkUser, subscribersName) { + return AppStorage.getOrCreate().setAndLink(key, defaultValue, linkUser, subscribersName); + } + /** + * @see setAndLink * @since 7 + * @deprecated */ static SetAndLink(key, defaultValue, linkUser, subscribersName) { - return AppStorage.GetOrCreate().setAndLink(key, defaultValue, linkUser, subscribersName); + return AppStorage.getOrCreate().setAndLink(key, defaultValue, linkUser, subscribersName); } /** - * create and return a one-way sync ('prop') to named property - * - * Same as @see LocalStorage.prop() - * - * @param propName name of source property in AppStorage - * @param propUser IPropertySubscriber to be notified when source changes, - * @param subscribersName the linkUser (subscriber) uses this name for the property - * this name will be used in propertyChange(propName) callback of IMultiPropertiesChangeSubscriber - * @returns SynchedPropertyOneWay{Simple|Object| object with given LocalStoage prop as its source. - * Apps can use SDK functions of base class SubscribedAbstractProperty - * return undefiend if named property does not already exist in AppStorage. - * @since 7 - */ + * create and return a one-way sync ('prop') to named property + * + * Same as @see LocalStorage.prop() + * + * @param propName name of source property in AppStorage + * @param propUser IPropertySubscriber to be notified when source changes, + * @param subscribersName the linkUser (subscriber) uses this name for the property + * this name will be used in propertyChange(propName) callback of IMultiPropertiesChangeSubscriber + * @returns SynchedPropertyOneWay{Simple|Object| object with given LocalStoage prop as its source. + * Apps can use SDK functions of base class SubscribedAbstractProperty + * return undefiend if named property does not already exist in AppStorage. + * @since 9 + */ + static prop(propName, propUser, subscribersName) { + return AppStorage.getOrCreate().prop(propName, propUser, subscribersName); + } + /** + * @see prop + * @since 7 + * @deprecated + */ static Prop(propName, propUser, subscribersName) { - return AppStorage.GetOrCreate().prop(propName, propUser, subscribersName); + return AppStorage.getOrCreate().prop(propName, propUser, subscribersName); } /** - * Like @see prop(), will create and initialize a new source property in AppStorage if missing - * - * Same as @see LocalStorage.setAndProp() - * - * @param propName name of source property in AppStorage - * @param defaultValue value to be used for initializing if new creating new property in AppStorage. - * default value must be of type S, must not be undefined or null. - * @param propUser IPropertySubscriber to be notified when returned 'prop' changes, - * @param subscribersName the propUser (subscriber) uses this name for the property - * this name will be used in propertyChange(propName) callback of IMultiPropertiesChangeSubscriber - * @returns SynchedPropertyOneWay{Simple|Object| object with given LocalStoage prop as its source. - * Apps can use SDK functions of base class SubscribedAbstractProperty - * - * @since 7 - */ + * Like @see prop(), will create and initialize a new source property in AppStorage if missing + * + * Same as @see LocalStorage.setAndProp() + * + * @param propName name of source property in AppStorage + * @param defaultValue value to be used for initializing if new creating new property in AppStorage. + * default value must be of type S, must not be undefined or null. + * @param propUser IPropertySubscriber to be notified when returned 'prop' changes, + * @param subscribersName the propUser (subscriber) uses this name for the property + * this name will be used in propertyChange(propName) callback of IMultiPropertiesChangeSubscriber + * @returns SynchedPropertyOneWay{Simple|Object| object with given LocalStoage prop as its source. + * Apps can use SDK functions of base class SubscribedAbstractProperty + * + * @since 9 + */ + static setAndProp(key, defaultValue, propUser, subscribersName) { + return AppStorage.getOrCreate().setAndProp(key, defaultValue, propUser, subscribersName); + } + /** + * @see setAndProp + * @since 7 + * @deprecated + */ static SetAndProp(key, defaultValue, propUser, subscribersName) { - return AppStorage.GetOrCreate().setAndProp(key, defaultValue, propUser, subscribersName); + return AppStorage.getOrCreate().setAndProp(key, defaultValue, propUser, subscribersName); } /** - * Check if AppStorge has a property with given name - * return true if prooperty with given name exists - * same as ES6 Map.prototype.has() - * - * Same as @see LocalStorage.has() - * - * @param propName searched property - * @returns true if property with such name exists in AppStorage - * - * @since 7 - */ + * Check if AppStorage has a property with given name + * return true if property with given name exists + * same as ES6 Map.prototype.has() + * + * Same as @see LocalStorage.has() + * + * @param propName searched property + * @returns true if property with such name exists in AppStorage + * + * @since 9 + */ + static has(key) { + return AppStorage.getOrCreate().has(key); + } + /** + * @see has() + * @since 7 + * @deprecated + */ static Has(key) { - return AppStorage.GetOrCreate().has(key); + return AppStorage.getOrCreate().has(key); } /** * Returns value of given property * return undefined if no property with this name * - * * @Same as see LocalStorage.get() * * @param propName * @returns property value if found or undefined * + * @since 9 + * + */ + static get(key) { + return AppStorage.getOrCreate().get(key); + } + /** + * @see get + * @since 7 + * @deprecated + * */ static Get(key) { - return AppStorage.GetOrCreate().get(key); + return AppStorage.getOrCreate().get(key); } /** * Set value of given property in AppStorage - * Methosd sets nothing and returns false if property with this name does not exist + * Method sets nothing and returns false if property with this name does not exist * or if newValue is `undefined` or `null` (`undefined`, `null` value are not allowed for state variables). * * Same as @see LocalStorage.set @@ -607,10 +657,18 @@ class AppStorage extends LocalStorage { * @param newValue must be of type T and must not be undefined or null * @returns true on success, i.e. when above conditions are satisfied, otherwise false * + * @since 9 + */ + static set(key, newValue) { + return AppStorage.getOrCreate().set(key, newValue); + } + /** + * @see set * @since 7 + * @deprecated */ static Set(key, newValue) { - return AppStorage.GetOrCreate().set(key, newValue); + return AppStorage.getOrCreate().set(key, newValue); } /** * Set value of given property, if it exists, @see set() . @@ -624,35 +682,51 @@ class AppStorage extends LocalStorage { * @param newValue must be of type T and must not be undefined or null * @returns true on success, i.e. when above conditions are satisfied, otherwise false * - * @since 7 + * @since 9 */ + static setOrCreate(key, newValue) { + AppStorage.getOrCreate().setOrCreate(key, newValue); + } + /** + * @see setOrCreate + * @since 7 + * @deprecated + */ static SetOrCreate(key, newValue) { - AppStorage.GetOrCreate().setOrCreate(key, newValue); + AppStorage.getOrCreate().setOrCreate(key, newValue); } /** - * Delete property from StorageBase - * Use with caution: - * Before deleting a prop from AppStorage all its subscribers need to - * unsubscribe from the property. - * This method fails and returns false if given property still has subscribers - * Another reason for failing is unkmown property. - * - * Developer advise: - * Subscribers are created with @see link(), @see prop() - * and also via @LocalStorageLink and @LocalStorageProp state variable decorators. - * That means as long as their is a @Component instance that uses such decorated variable - * or a sync relationship with a SubscribedAbstractProperty variable the property can nit - * (and also should not!) be deleted from AppStorage. - * - * Same as @see LocalStorage.delete() - * - * @param propName - * @returns false if method failed - * - * @since 7 + * Delete property from StorageBase + * Use with caution: + * Before deleting a prop from AppStorage all its subscribers need to + * unsubscribe from the property. + * This method fails and returns false if given property still has subscribers + * Another reason for failing is unkmown property. + * + * Developer advise: + * Subscribers are created with @see link(), @see prop() + * and also via @LocalStorageLink and @LocalStorageProp state variable decorators. + * That means as long as their is a @Component instance that uses such decorated variable + * or a sync relationship with a SubscribedAbstractProperty variable the property can nit + * (and also should not!) be deleted from AppStorage. + * + * Same as @see LocalStorage.delete() + * + * @param propName + * @returns false if method failed + * + * @since 9 + */ + static delete(key) { + return AppStorage.getOrCreate().delete(key); + } + /** + * @see delete + * @since 7 + * @deprecated */ static Delete(key) { - return AppStorage.GetOrCreate().delete(key); + return AppStorage.getOrCreate().delete(key); } /** * Provide names of all properties in AppStorage @@ -662,53 +736,77 @@ class AppStorage extends LocalStorage { * * @returns return a Map Iterator * - * @since 7 + * @since 9 */ + static keys() { + return AppStorage.getOrCreate().keys(); + } + /** + * @see keys + * @since 7 + * @deprecated + */ static Keys() { - return AppStorage.GetOrCreate().keys(); + return AppStorage.getOrCreate().keys(); } /** - * Returns number of properties in AppStorage - * same as Map.prototype.size() - * - * Same as @see LocalStorage.size() - * - * @param propName - * @returns return number of properties - * - * @since 7 - */ + * Returns number of properties in AppStorage + * same as Map.prototype.size() + * + * Same as @see LocalStorage.size() + * + * @param propName + * @returns return number of properties + * + * @since 9 + */ + static size() { + return AppStorage.getOrCreate().size(); + } + /** + * @see size + * @since 7 + * @deprecated + */ static Size() { - return AppStorage.GetOrCreate().size(); + return AppStorage.getOrCreate().size(); } /** - * delete all properties from the AppStorage - * - * @see delete(), same as @see LocalStorage.clear() - * - * precondition is that there are no subscribers. - * method returns false and deletes no poperties if there is any property - * that still has subscribers - * - * @since 7 - */ + * delete all properties from the AppStorage + * + * @see delete(), same as @see LocalStorage.clear() + * + * precondition is that there are no subscribers. + * method returns false and deletes no poperties if there is any property + * that still has subscribers + * + * @since 9 + */ + static clear() { + return AppStorage.getOrCreate().clear(); + } + /** + * @see clear + * @since 7 + * @deprecated + */ static Clear() { - return AppStorage.GetOrCreate().clear(); + return AppStorage.getOrCreate().clear(); } /** - * Same as @see Clear(). - * - * @since 7, depreciated, used Clear() instead! - * - */ + * Same as @see clear(). + * + * @since 7, deprecated, used clear() instead! + * + */ static StaticClear() { - return AppStorage.Clear(); + return AppStorage.clear(); } /** * not a public / sdk function */ - static AboutToBeDeleted() { - AppStorage.GetOrCreate().aboutToBeDeleted(); + static aboutToBeDeleted() { + AppStorage.getOrCreate().aboutToBeDeleted(); } /** * return number of subscribers to named property @@ -716,8 +814,8 @@ class AppStorage extends LocalStorage { * * not a public / sdk function */ - static NumberOfSubscribersTo(propName) { - return AppStorage.GetOrCreate().numberOfSubscrbersTo(propName); + static numberOfSubscribersTo(propName) { + return AppStorage.getOrCreate().numberOfSubscrbersTo(propName); } /** * Subscribe to value change notifications of named property @@ -732,52 +830,68 @@ class AppStorage extends LocalStorage { * @param subscriber object that implements ISinglePropertyChangeSubscriber interface * @returns false if named property does not exist * + * @since 9 + */ + static subscribeToChangesOf(propName, subscriber) { + return AppStorage.getOrCreate().subscribeToChangesOf(propName, subscriber); + } + /** + * @see subscribeToChangesOf * @since 7 + * @deprecated */ static SubscribeToChangesOf(propName, subscriber) { - return AppStorage.GetOrCreate().subscribeToChangesOf(propName, subscriber); + return AppStorage.getOrCreate().subscribeToChangesOf(propName, subscriber); } /** - * inverse of @see SubscribeToChangesOf, - * same as @see LocalStorage.subscribeToChangesOf() - * - * @param propName property in AppStorage to subscribe to - * @param subscriberId id of the subscrber passed to @see subscribeToChangesOf - * @returns false if named property does not exist - * - * @since 7 - */ + * inverse of @see SubscribeToChangesOf, + * same as @see LocalStorage.subscribeToChangesOf() + * + * @param propName property in AppStorage to subscribe to + * @param subscriberId id of the subscrber passed to @see subscribeToChangesOf + * @returns false if named property does not exist + * + * @since 9 + */ + static unsubscribeFromChangesOf(propName, subscriberId) { + return AppStorage.getOrCreate().unsubscribeFromChangesOf(propName, subscriberId); + } + /** + * @see unsubscribeFromChangesOf + * @since 7 + * @deprecated + */ static UnsubscribeFromChangesOf(propName, subscriberId) { - return AppStorage.GetOrCreate().unsubscribeFromChangesOf(propName, subscriberId); + return AppStorage.getOrCreate().unsubscribeFromChangesOf(propName, subscriberId); } /** - * Unimplemenrted, currently all properties of AppStorage are mutable. + * Unimplemented, currently all properties of AppStorage are mutable. * - * @since 7, depreciated + * @since 7, deprecated */ static IsMutable(key) { return true; } /** - * not a public / sdk function - */ - static __CreateSync(storagePropName, defaultValue, factoryFunc) { - return AppStorage.GetOrCreate().__createSync(storagePropName, defaultValue, factoryFunc); + * not a public / sdk function + */ + static __createSync(storagePropName, defaultValue, factoryFunc) { + return AppStorage.getOrCreate().__createSync(storagePropName, defaultValue, factoryFunc); } /** - * not a public / sdk function - */ - static GetOrCreate() { - if (!AppStorage.Instance_) { - stateMgmtConsole.warn("AppStorage instance missing. Use AppStorage.CreateInstance(initObj). Creating instance without any initialization."); - AppStorage.Instance_ = new AppStorage({}); + * not a public / sdk function + */ + static getOrCreate() { + if (!AppStorage.instance_) { + stateMgmtConsole.warn("AppStorage instance missing. Use AppStorage.createInstance(initObj). Creating instance without any initialization."); + AppStorage.instance_ = new AppStorage({}); } - return AppStorage.Instance_; + return AppStorage.instance_; } } // instance functions below: // Should all be protected, but TS lang does not allow access from static member to protected member -AppStorage.Instance_ = undefined; +AppStorage.instance_ = undefined; /* * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); @@ -1142,7 +1256,7 @@ class SubscribaleAbstract { } } /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -1179,34 +1293,34 @@ class PersistentStorage { * internal function, not part of the SDK * */ - static ConfigureBackend(storage) { - PersistentStorage.Storage_ = storage; + static configureBackend(storage) { + PersistentStorage.storage_ = storage; } /** * private, use static functions! */ - static GetOrCreate() { - if (PersistentStorage.Instance_) { + static getOrCreate() { + if (PersistentStorage.instance_) { // already initialized - return PersistentStorage.Instance_; + return PersistentStorage.instance_; } - PersistentStorage.Instance_ = new PersistentStorage(); - return PersistentStorage.Instance_; + PersistentStorage.instance_ = new PersistentStorage(); + return PersistentStorage.instance_; } /** * * internal function, not part of the SDK */ - static AboutToBeDeleted() { - if (!PersistentStorage.Instance_) { + static aboutToBeDeleted() { + if (!PersistentStorage.instance_) { return; } - PersistentStorage.GetOrCreate().aboutToBeDeleted(); - PersistentStorage.Instance_ = undefined; + PersistentStorage.getOrCreate().aboutToBeDeleted(); + PersistentStorage.instance_ = undefined; } /** * Add property 'key' to AppStorage properties whose current value will be - * persistemt. + * persistent. * If AppStorage does not include this property it will be added and initializes * with given value * @@ -1216,30 +1330,51 @@ class PersistentStorage { * @param defaultValue If AppStorage does not include this property it will be initialized with this value * */ + static persistProp(key, defaultValue) { + PersistentStorage.getOrCreate().persistProp(key, defaultValue); + } + /** + * @see persistProp + * @deprecated + */ static PersistProp(key, defaultValue) { - PersistentStorage.GetOrCreate().persistProp(key, defaultValue); + PersistentStorage.getOrCreate().persistProp(key, defaultValue); } /** - * Reverse of @see PersistProp + * Reverse of @see persistProp * @param key no longer persist the property named key * * @since 9 */ + static deleteProp(key) { + PersistentStorage.getOrCreate().deleteProp(key); + } + /** + * @see deleteProp + * @deprecated + */ static DeleteProp(key) { - PersistentStorage.GetOrCreate().deleteProp(key); + PersistentStorage.getOrCreate().deleteProp(key); } /** * Persist given AppStorage properties with given names. * If a property does not exist in AppStorage, add it and initialize it with given value - * works as @see PersistProp for multiple properties. + * works as @see persistProp for multiple properties. * * @param properties * * @since 9 * */ + static persistProps(properties) { + PersistentStorage.getOrCreate().persistProps(properties); + } + /** + * @see persistProps + * @deprecated + */ static PersistProps(properties) { - PersistentStorage.GetOrCreate().persistProps(properties); + PersistentStorage.getOrCreate().persistProps(properties); } /** * Inform persisted AppStorage property names @@ -1247,9 +1382,9 @@ class PersistentStorage { * * @since 9 */ - static Keys() { + static keys() { let result = []; - const it = PersistentStorage.GetOrCreate().keys(); + const it = PersistentStorage.getOrCreate().keys(); let val = it.next(); while (!val.done) { result.push(val.value); @@ -1257,6 +1392,13 @@ class PersistentStorage { } return result; } + /** + * @see keys + * @deprecated + */ + static Keys() { + return PersistentStorage.keys(); + } /** * This methid offers a way to force writing the property value with given * key to persistent storage. @@ -1270,9 +1412,17 @@ class PersistentStorage { * @since 9 * */ + static notifyHasChanged(propName) { + + PersistentStorage.storage_.set(propName, PersistentStorage.getOrCreate().links_.get(propName).get()); + } + /** + * @see notifyHasChanged + * @deprecated + */ static NotifyHasChanged(propName) { - PersistentStorage.Storage_.set(propName, PersistentStorage.GetOrCreate().links_.get(propName).get()); + PersistentStorage.storage_.set(propName, PersistentStorage.getOrCreate().links_.get(propName).get()); } keys() { return this.links_.keys(); @@ -1281,7 +1431,7 @@ class PersistentStorage { if (this.persistProp1(propName, defaultValue)) { // persist new prop - PersistentStorage.Storage_.set(propName, this.links_.get(propName).get()); + PersistentStorage.storage_.set(propName, this.links_.get(propName).get()); } } // helper function to persist a property @@ -1295,13 +1445,13 @@ class PersistentStorage { stateMgmtConsole.warn(`PersistentStorage: persistProp: ${propName} is already persisted`); return false; } - let link = AppStorage.Link(propName, this); + let link = AppStorage.link(propName, this); if (link) { this.links_.set(propName, link); } else { - let newValue = PersistentStorage.Storage_.get(propName); + let newValue = PersistentStorage.storage_.get(propName); let returnValue; if (!newValue) { @@ -1310,7 +1460,7 @@ class PersistentStorage { else { returnValue = newValue; } - link = AppStorage.SetAndLink(propName, returnValue, this); + link = AppStorage.setAndLink(propName, returnValue, this); this.links_.set(propName, link); } @@ -1325,7 +1475,7 @@ class PersistentStorage { if (link) { link.aboutToBeDeleted(); this.links_.delete(propName); - PersistentStorage.Storage_.delete(propName); + PersistentStorage.storage_.delete(propName); } else { @@ -1335,7 +1485,7 @@ class PersistentStorage { write() { this.links_.forEach((link, propName, map) => { - PersistentStorage.Storage_.set(propName, link.get()); + PersistentStorage.storage_.set(propName, link.get()); }); } propertyHasChanged(info) { @@ -1351,16 +1501,16 @@ class PersistentStorage { }); this.links_.clear(); SubscriberManager.Delete(this.id__()); - PersistentStorage.Storage_.clear(); + PersistentStorage.storage_.clear(); } id__() { return this.id_; } } -PersistentStorage.Instance_ = undefined; +PersistentStorage.instance_ = undefined; ; /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -1382,37 +1532,72 @@ PersistentStorage.Instance_ = undefined; class Environment { constructor() { this.props_ = new Map(); - Environment.EnvBackend_.onValueChanged(this.onValueChanged.bind(this)); + Environment.envBackend_.onValueChanged(this.onValueChanged.bind(this)); } - static GetOrCreate() { - if (Environment.Instance_) { + static getOrCreate() { + if (Environment.instance_) { // already initialized - return Environment.Instance_; + return Environment.instance_; } - Environment.Instance_ = new Environment(); - return Environment.Instance_; + Environment.instance_ = new Environment(); + return Environment.instance_; + } + static configureBackend(envBackend) { + Environment.envBackend_ = envBackend; } + /** + * @see configureBackend + * @deprecated + */ static ConfigureBackend(envBackend) { - Environment.EnvBackend_ = envBackend; + Environment.envBackend_ = envBackend; } - static AboutToBeDeleted() { - if (!Environment.Instance_) { + static aboutToBeDeleted() { + if (!Environment.instance_) { return; } - Environment.GetOrCreate().aboutToBeDeleted(); - Environment.Instance_ = undefined; + Environment.getOrCreate().aboutToBeDeleted(); + Environment.instance_ = undefined; } + /** + * @see aboutToBeDeleted + * @deprecated + */ + static AboutToBeDeleted() { + Environment.aboutToBeDeleted(); + } + static envProp(key, value) { + return Environment.getOrCreate().envProp(key, value); + } + /** + * @see envProp + * @deprecated + */ static EnvProp(key, value) { - return Environment.GetOrCreate().envProp(key, value); + return Environment.getOrCreate().envProp(key, value); + } + static envProps(props) { + Environment.getOrCreate().envProps(props); } + /** + * @see envProps + * @deprecated + */ static EnvProps(props) { - Environment.GetOrCreate().envProps(props); + Environment.getOrCreate().envProps(props); + } + static keys() { + return Environment.getOrCreate().keys(); } + /** + * @see keys + * @deprecated + */ static Keys() { - return Environment.GetOrCreate().keys(); + return Environment.getOrCreate().keys(); } envProp(key, value) { - let prop = AppStorage.Prop(key); + let prop = AppStorage.prop(key); if (prop) { stateMgmtConsole.warn(`Environment: envProp '${key}': Property already exists in AppStorage. Not using environment property.`); return false; @@ -1420,27 +1605,27 @@ class Environment { let tmp; switch (key) { case "accessibilityEnabled": - tmp = Environment.EnvBackend_.getAccessibilityEnabled(); + tmp = Environment.envBackend_.getAccessibilityEnabled(); break; case "colorMode": - tmp = Environment.EnvBackend_.getColorMode(); + tmp = Environment.envBackend_.getColorMode(); break; case "fontScale": - tmp = Environment.EnvBackend_.getFontScale(); + tmp = Environment.envBackend_.getFontScale(); break; case "fontWeightScale": - tmp = Environment.EnvBackend_.getFontWeightScale().toFixed(2); + tmp = Environment.envBackend_.getFontWeightScale().toFixed(2); break; case "layoutDirection": - tmp = Environment.EnvBackend_.getLayoutDirection(); + tmp = Environment.envBackend_.getLayoutDirection(); break; case "languageCode": - tmp = Environment.EnvBackend_.getLanguageCode(); + tmp = Environment.envBackend_.getLanguageCode(); break; default: tmp = value; } - prop = AppStorage.SetAndProp(key, tmp); + prop = AppStorage.setAndProp(key, tmp); this.props_.set(key, prop); } @@ -1461,7 +1646,7 @@ class Environment { return result; } onValueChanged(key, value) { - let ok = AppStorage.Set(key, value); + let ok = AppStorage.set(key, value); if (ok) { } @@ -1472,11 +1657,11 @@ class Environment { aboutToBeDeleted() { this.props_.forEach((val, key, map) => { val.aboutToBeDeleted(); - AppStorage.Delete(key); + AppStorage.delete(key); }); } } -Environment.Instance_ = undefined; +Environment.instance_ = undefined; /* * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); @@ -1523,7 +1708,7 @@ class stateMgmtTrace { } } /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -1571,7 +1756,7 @@ class DistributedStorage { stateMgmtConsole.warn(`DistributedStorage: linkProp: ${propName} is already exist`); return false; } - let link = AppStorage.Link(propName, this); + let link = AppStorage.link(propName, this); if (link) { this.links_.set(propName, link); @@ -1589,7 +1774,7 @@ class DistributedStorage { returnValue = newValue; } } - link = AppStorage.SetAndLink(propName, returnValue, this); + link = AppStorage.setAndLink(propName, returnValue, this); this.links_.set(propName, link); } @@ -3569,7 +3754,7 @@ class SynchedPropertyNesedObjectPU extends ObservedPropertyObjectAbstractPU { } } /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -4044,14 +4229,14 @@ class ViewPU extends NativeViewPartialUpdate { * @returns SynchedPropertySimple/ObjectTwoWay/PU */ createStorageLink(storagePropName, defaultValue, viewVariableName) { - return AppStorage.__CreateSync(storagePropName, defaultValue, (source) => (source === undefined) + return AppStorage.__createSync(storagePropName, defaultValue, (source) => (source === undefined) ? undefined : (source instanceof ObservedPropertySimple) ? new SynchedPropertySimpleTwoWayPU(source, this, viewVariableName) : new SynchedPropertyObjectTwoWayPU(source, this, viewVariableName)); } createStorageProp(storagePropName, defaultValue, viewVariableName) { - return AppStorage.__CreateSync(storagePropName, defaultValue, (source) => (source === undefined) + return AppStorage.__createSync(storagePropName, defaultValue, (source) => (source === undefined) ? undefined : (source instanceof ObservedPropertySimple) ? new SynchedPropertySimpleOneWayPU(source, this, viewVariableName) @@ -4153,7 +4338,7 @@ function makeBuilderParameterProxy(builderName, source) { }); // new Proxy } /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -4167,6 +4352,6 @@ function makeBuilderParameterProxy(builderName, source) { * limitations under the License. */ -PersistentStorage.ConfigureBackend(new Storage()); -Environment.ConfigureBackend(new EnvironmentSetting()); +PersistentStorage.configureBackend(new Storage()); +Environment.configureBackend(new EnvironmentSetting()); diff --git a/frameworks/bridge/declarative_frontend/state_mgmt/src/index.ts b/frameworks/bridge/declarative_frontend/state_mgmt/src/index.ts index a60cacb0f8e761c50ed674b5fb0f14c36379e35b..8320b70d921c44070f1dbf0849d0305cf89981e8 100644 --- a/frameworks/bridge/declarative_frontend/state_mgmt/src/index.ts +++ b/frameworks/bridge/declarative_frontend/state_mgmt/src/index.ts @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -15,7 +15,7 @@ stateMgmtConsole.info("ACE State Management component is initiaizing ...") -PersistentStorage.ConfigureBackend(new Storage()); +PersistentStorage.configureBackend(new Storage()); -Environment.ConfigureBackend(new EnvironmentSetting()); +Environment.configureBackend(new EnvironmentSetting()); diff --git a/frameworks/bridge/declarative_frontend/state_mgmt/src/lib/common/distributed_storage.ts b/frameworks/bridge/declarative_frontend/state_mgmt/src/lib/common/distributed_storage.ts index 12faff937c99a313917ec43a441fa2163199298e..68c1cdd5641dc17e4e3830d7a5a9e7ba90e56137 100644 --- a/frameworks/bridge/declarative_frontend/state_mgmt/src/lib/common/distributed_storage.ts +++ b/frameworks/bridge/declarative_frontend/state_mgmt/src/lib/common/distributed_storage.ts @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -65,7 +65,7 @@ class DistributedStorage implements IMultiPropertiesChangeSubscriber { stateMgmtConsole.warn(`DistributedStorage: linkProp: ${propName} is already exist`); return false; } - let link = AppStorage.Link(propName, this); + let link = AppStorage.link(propName, this); if (link) { stateMgmtConsole.debug(`DistributedStorage: linkProp ${propName} in AppStorage, using that`); this.links_.set(propName, link); @@ -83,7 +83,7 @@ class DistributedStorage implements IMultiPropertiesChangeSubscriber { returnValue = newValue; } } - link = AppStorage.SetAndLink(propName, returnValue, this); + link = AppStorage.setAndLink(propName, returnValue, this); this.links_.set(propName, link); stateMgmtConsole.debug(`DistributedStorage: created new linkProp prop for ${propName}`); } diff --git a/frameworks/bridge/declarative_frontend/state_mgmt/src/lib/partial_update/pu_view.ts b/frameworks/bridge/declarative_frontend/state_mgmt/src/lib/partial_update/pu_view.ts index fa0bfeb55471d8c41ff94c6b891169269cf2a92b..c33845b867d641ed35ab3cc7513ba1cc4efb0e1c 100644 --- a/frameworks/bridge/declarative_frontend/state_mgmt/src/lib/partial_update/pu_view.ts +++ b/frameworks/bridge/declarative_frontend/state_mgmt/src/lib/partial_update/pu_view.ts @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -586,7 +586,7 @@ abstract class ViewPU extends NativeViewPartialUpdate * @returns SynchedPropertySimple/ObjectTwoWay/PU */ public createStorageLink(storagePropName: string, defaultValue: T, viewVariableName: string): ObservedPropertyAbstractPU { - return AppStorage.__CreateSync(storagePropName, defaultValue, + return AppStorage.__createSync(storagePropName, defaultValue, (source: ObservedPropertyAbstract) => (source === undefined) ? undefined : (source instanceof ObservedPropertySimple) @@ -596,7 +596,7 @@ abstract class ViewPU extends NativeViewPartialUpdate } public createStorageProp(storagePropName: string, defaultValue: T, viewVariableName: string): ObservedPropertyAbstractPU { - return AppStorage.__CreateSync(storagePropName, defaultValue, + return AppStorage.__createSync(storagePropName, defaultValue, (source: ObservedPropertyAbstract) => (source === undefined) ? undefined : (source instanceof ObservedPropertySimple) diff --git a/frameworks/bridge/declarative_frontend/state_mgmt/src/lib/sdk/app_storage.ts b/frameworks/bridge/declarative_frontend/state_mgmt/src/lib/sdk/app_storage.ts index c1be4bf6fad75be855f07e4f701b3a970fb00025..f669b6918971f079e3fb7e656115cb44a979b7f6 100644 --- a/frameworks/bridge/declarative_frontend/state_mgmt/src/lib/sdk/app_storage.ts +++ b/frameworks/bridge/declarative_frontend/state_mgmt/src/lib/sdk/app_storage.ts @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -25,150 +25,213 @@ */ class AppStorage extends LocalStorage { - /** - * create and initialize singleton - * initialzie with all properties and their values that Object.keys(params) returns - * Property values must not be undefined. - * - * not a public / sdk function - */ - public static CreateSingleton(initializingPropersties?: Object): void { - if (!AppStorage.Instance_) { - stateMgmtConsole.debug("Creating AppStorage instance."); - AppStorage.Instance_ = new AppStorage(initializingPropersties); - } else { - stateMgmtConsole.error("AppStorage.CreateNewInstance(..): instance exists already, internal error!") - } - } - - - /** - * create and return a two-way sync "(link") to named property - * - * Same as @see LocalStorage.link() - * - * @param propName name of source property in AppStorage - * @param linkUser IPropertySubscriber to be notified when source changes, - * @param subscribersName the linkUser (subscriber) uses this name for the property - * this name will be used in propertyChange(propName) callback of IMultiPropertiesChangeSubscriber - * @returns SynchedPropertyTwoWay{Simple|Object| object with given LocalStoage prop as its source. - * Apps can use SDK functions of base class SubscribedAbstractProperty - * return undefiend if named property does not already exist in AppStorage - * - * @since 7 - */ - public static Link(key: string, linkUser?: IPropertySubscriber, subscribersName?: string): SubscribedAbstractProperty { - return AppStorage.GetOrCreate().link(key, linkUser, subscribersName); - } + /** + * create and initialize singleton + * initialzie with all properties and their values that Object.keys(params) returns + * Property values must not be undefined. + * + * not a public / sdk function + */ + public static createSingleton(initializingPropersties?: Object): void { + if (!AppStorage.instance_) { + stateMgmtConsole.debug("Creating AppStorage instance."); + AppStorage.instance_ = new AppStorage(initializingPropersties); + } else { + stateMgmtConsole.error("AppStorage.createNewInstance(..): instance exists already, internal error!") + } + } - /** - * Like @see link(), but will create and initialize a new source property in LocalStorge if missing - * - * Same as @see LocalStorage.setAndLink() - * - * @param propName name of source property in AppStorage - * @param defaultValue value to be used for initializing if new creating new property in AppStorage - * default value must be of type S, must not be undefined or null. - * @param linkUser IPropertySubscriber to be notified when return 'link' changes, - * @param subscribersName the linkUser (subscriber) uses this name for the property - * this name will be used in propertyChange(propName) callback of IMultiPropertiesChangeSubscriber - * @returns SynchedPropertyTwoWay{Simple|Object| object with given LocalStoage prop as its source. - * Apps can use SDK functions of base class SubscribedAbstractProperty - * - * @since 7 - */ - public static SetAndLink(key: string, defaultValue: T, linkUser?: IPropertySubscriber, subscribersName?: string): SubscribedAbstractProperty { - return AppStorage.GetOrCreate().setAndLink(key, defaultValue, linkUser, subscribersName); - } + /** + * create and return a two-way sync "(link") to named property + * + * Same as @see LocalStorage.link() + * + * @param propName name of source property in AppStorage + * @param linkUser IPropertySubscriber to be notified when source changes, + * @param subscribersName the linkUser (subscriber) uses this name for the property + * this name will be used in propertyChange(propName) callback of IMultiPropertiesChangeSubscriber + * @returns SynchedPropertyTwoWay{Simple|Object| object with given LocalStoage prop as its source. + * Apps can use SDK functions of base class SubscribedAbstractProperty + * return undefiend if named property does not already exist in AppStorage + * + * @since 9 + */ + public static link(key: string, linkUser?: IPropertySubscriber, subscribersName?: string): SubscribedAbstractProperty { + return AppStorage.getOrCreate().link(key, linkUser, subscribersName); + } /** - * create and return a one-way sync ('prop') to named property - * - * Same as @see LocalStorage.prop() - * - * @param propName name of source property in AppStorage - * @param propUser IPropertySubscriber to be notified when source changes, - * @param subscribersName the linkUser (subscriber) uses this name for the property - * this name will be used in propertyChange(propName) callback of IMultiPropertiesChangeSubscriber - * @returns SynchedPropertyOneWay{Simple|Object| object with given LocalStoage prop as its source. - * Apps can use SDK functions of base class SubscribedAbstractProperty - * return undefiend if named property does not already exist in AppStorage. - * @since 7 - */ - public static Prop(propName: string, propUser?: IPropertySubscriber, subscribersName?: string): SubscribedAbstractProperty { - return AppStorage.GetOrCreate().prop(propName, propUser, subscribersName); - } + * @see link + * @since 7 + * @deprecated + */ + public static Link(key: string, linkUser?: IPropertySubscriber, subscribersName?: string): SubscribedAbstractProperty { + return AppStorage.getOrCreate().link(key, linkUser, subscribersName); + } /** - * Like @see prop(), will create and initialize a new source property in AppStorage if missing - * - * Same as @see LocalStorage.setAndProp() - * - * @param propName name of source property in AppStorage - * @param defaultValue value to be used for initializing if new creating new property in AppStorage. - * default value must be of type S, must not be undefined or null. - * @param propUser IPropertySubscriber to be notified when returned 'prop' changes, - * @param subscribersName the propUser (subscriber) uses this name for the property - * this name will be used in propertyChange(propName) callback of IMultiPropertiesChangeSubscriber - * @returns SynchedPropertyOneWay{Simple|Object| object with given LocalStoage prop as its source. - * Apps can use SDK functions of base class SubscribedAbstractProperty - * - * @since 7 - */ - public static SetAndProp(key: string, defaultValue: S, propUser?: IPropertySubscriber, subscribersName?: string): SubscribedAbstractProperty { - return AppStorage.GetOrCreate().setAndProp(key, defaultValue, propUser, subscribersName); - } + * Like @see link(), but will create and initialize a new source property in LocalStorage if missing + * + * Same as @see LocalStorage.setAndLink() + * + * @param propName name of source property in AppStorage + * @param defaultValue value to be used for initializing if new creating new property in AppStorage + * default value must be of type S, must not be undefined or null. + * @param linkUser IPropertySubscriber to be notified when return 'link' changes, + * @param subscribersName the linkUser (subscriber) uses this name for the property + * this name will be used in propertyChange(propName) callback of IMultiPropertiesChangeSubscriber + * @returns SynchedPropertyTwoWay{Simple|Object| object with given LocalStoage prop as its source. + * Apps can use SDK functions of base class SubscribedAbstractProperty + * + * @since 9 + */ + public static setAndLink(key: string, defaultValue: T, linkUser?: IPropertySubscriber, subscribersName?: string): SubscribedAbstractProperty { + return AppStorage.getOrCreate().setAndLink(key, defaultValue, linkUser, subscribersName); + } + /** + * @see setAndLink + * @since 7 + * @deprecated + */ + public static SetAndLink(key: string, defaultValue: T, linkUser?: IPropertySubscriber, subscribersName?: string): SubscribedAbstractProperty { + return AppStorage.getOrCreate().setAndLink(key, defaultValue, linkUser, subscribersName); + } - /** - * Check if AppStorge has a property with given name - * return true if prooperty with given name exists - * same as ES6 Map.prototype.has() - * - * Same as @see LocalStorage.has() - * - * @param propName searched property - * @returns true if property with such name exists in AppStorage - * - * @since 7 - */ - public static Has(key: string): boolean { - return AppStorage.GetOrCreate().has(key); - } + /** + * create and return a one-way sync ('prop') to named property + * + * Same as @see LocalStorage.prop() + * + * @param propName name of source property in AppStorage + * @param propUser IPropertySubscriber to be notified when source changes, + * @param subscribersName the linkUser (subscriber) uses this name for the property + * this name will be used in propertyChange(propName) callback of IMultiPropertiesChangeSubscriber + * @returns SynchedPropertyOneWay{Simple|Object| object with given LocalStoage prop as its source. + * Apps can use SDK functions of base class SubscribedAbstractProperty + * return undefiend if named property does not already exist in AppStorage. + * @since 9 + */ + public static prop(propName: string, propUser?: IPropertySubscriber, subscribersName?: string): SubscribedAbstractProperty { + return AppStorage.getOrCreate().prop(propName, propUser, subscribersName); + } + /** + * @see prop + * @since 7 + * @deprecated + */ + public static Prop(propName: string, propUser?: IPropertySubscriber, subscribersName?: string): SubscribedAbstractProperty { + return AppStorage.getOrCreate().prop(propName, propUser, subscribersName); + } - /** - * Returns value of given property - * return undefined if no property with this name - * - * - * @Same as see LocalStorage.get() - * - * @param propName - * @returns property value if found or undefined - * - */ - public static Get(key: string): T | undefined { - return AppStorage.GetOrCreate().get(key); - } - - /** - * Set value of given property in AppStorage - * Methosd sets nothing and returns false if property with this name does not exist - * or if newValue is `undefined` or `null` (`undefined`, `null` value are not allowed for state variables). - * - * Same as @see LocalStorage.set - * - * @param propName - * @param newValue must be of type T and must not be undefined or null - * @returns true on success, i.e. when above conditions are satisfied, otherwise false - * + /** + * Like @see prop(), will create and initialize a new source property in AppStorage if missing + * + * Same as @see LocalStorage.setAndProp() + * + * @param propName name of source property in AppStorage + * @param defaultValue value to be used for initializing if new creating new property in AppStorage. + * default value must be of type S, must not be undefined or null. + * @param propUser IPropertySubscriber to be notified when returned 'prop' changes, + * @param subscribersName the propUser (subscriber) uses this name for the property + * this name will be used in propertyChange(propName) callback of IMultiPropertiesChangeSubscriber + * @returns SynchedPropertyOneWay{Simple|Object| object with given LocalStoage prop as its source. + * Apps can use SDK functions of base class SubscribedAbstractProperty + * + * @since 9 + */ + public static setAndProp(key: string, defaultValue: S, propUser?: IPropertySubscriber, subscribersName?: string): SubscribedAbstractProperty { + return AppStorage.getOrCreate().setAndProp(key, defaultValue, propUser, subscribersName); + } + + /** + * @see setAndProp + * @since 7 + * @deprecated + */ + public static SetAndProp(key: string, defaultValue: S, propUser?: IPropertySubscriber, subscribersName?: string): SubscribedAbstractProperty { + return AppStorage.getOrCreate().setAndProp(key, defaultValue, propUser, subscribersName); + } + + + /** + * Check if AppStorage has a property with given name + * return true if property with given name exists + * same as ES6 Map.prototype.has() + * + * Same as @see LocalStorage.has() + * + * @param propName searched property + * @returns true if property with such name exists in AppStorage + * + * @since 9 + */ + public static has(key: string): boolean { + return AppStorage.getOrCreate().has(key); + } + + /** + * @see has() * @since 7 + * @deprecated */ - public static Set(key: string, newValue: T): boolean { - return AppStorage.GetOrCreate().set(key, newValue); - } + public static Has(key: string): boolean { + return AppStorage.getOrCreate().has(key); + } + + /** + * Returns value of given property + * return undefined if no property with this name + * + * @Same as see LocalStorage.get() + * + * @param propName + * @returns property value if found or undefined + * + * @since 9 + * + */ + public static get(key: string): T | undefined { + return AppStorage.getOrCreate().get(key); + } + + /** + * @see get + * @since 7 + * @deprecated + * + */ + public static Get(key: string): T | undefined { + return AppStorage.getOrCreate().get(key); + } + + /** + * Set value of given property in AppStorage + * Method sets nothing and returns false if property with this name does not exist + * or if newValue is `undefined` or `null` (`undefined`, `null` value are not allowed for state variables). + * + * Same as @see LocalStorage.set + * + * @param propName + * @param newValue must be of type T and must not be undefined or null + * @returns true on success, i.e. when above conditions are satisfied, otherwise false + * + * @since 9 + */ + public static set(key: string, newValue: T): boolean { + return AppStorage.getOrCreate().set(key, newValue); + } + + /** + * @see set + * @since 7 + * @deprecated + */ + public static Set(key: string, newValue: T): boolean { + return AppStorage.getOrCreate().set(key, newValue); + } /** * Set value of given property, if it exists, @see set() . @@ -182,188 +245,250 @@ class AppStorage extends LocalStorage { * @param newValue must be of type T and must not be undefined or null * @returns true on success, i.e. when above conditions are satisfied, otherwise false * - * @since 7 + * @since 9 */ - public static SetOrCreate(key: string, newValue: T): void { - AppStorage.GetOrCreate().setOrCreate(key, newValue); - } - - - /** - * Delete property from StorageBase - * Use with caution: - * Before deleting a prop from AppStorage all its subscribers need to - * unsubscribe from the property. - * This method fails and returns false if given property still has subscribers - * Another reason for failing is unkmown property. - * - * Developer advise: - * Subscribers are created with @see link(), @see prop() - * and also via @LocalStorageLink and @LocalStorageProp state variable decorators. - * That means as long as their is a @Component instance that uses such decorated variable - * or a sync relationship with a SubscribedAbstractProperty variable the property can nit - * (and also should not!) be deleted from AppStorage. - * - * Same as @see LocalStorage.delete() - * - * @param propName - * @returns false if method failed - * - * @since 7 - */ - public static Delete(key: string): boolean { - return AppStorage.GetOrCreate().delete(key); - } - - /** - * Provide names of all properties in AppStorage - * same as ES6 Map.prototype.keys() - * - * Same as @see LocalStorage.keys() - * - * @returns return a Map Iterator - * - * @since 7 - */ - public static Keys(): IterableIterator { - return AppStorage.GetOrCreate().keys(); - } + public static setOrCreate(key: string, newValue: T): void { + AppStorage.getOrCreate().setOrCreate(key, newValue); + } + /** + * @see setOrCreate + * @since 7 + * @deprecated + */ + public static SetOrCreate(key: string, newValue: T): void { + AppStorage.getOrCreate().setOrCreate(key, newValue); + } - /** - * Returns number of properties in AppStorage - * same as Map.prototype.size() - * - * Same as @see LocalStorage.size() - * - * @param propName - * @returns return number of properties - * - * @since 7 - */ - public static Size(): number { - return AppStorage.GetOrCreate().size(); - } - /** - * delete all properties from the AppStorage - * - * @see delete(), same as @see LocalStorage.clear() - * - * precondition is that there are no subscribers. - * method returns false and deletes no poperties if there is any property - * that still has subscribers - * - * @since 7 - */ - public static Clear(): boolean { - return AppStorage.GetOrCreate().clear(); - } - - /** - * Same as @see Clear(). - * - * @since 7, depreciated, used Clear() instead! - * + /** + * Delete property from StorageBase + * Use with caution: + * Before deleting a prop from AppStorage all its subscribers need to + * unsubscribe from the property. + * This method fails and returns false if given property still has subscribers + * Another reason for failing is unkmown property. + * + * Developer advise: + * Subscribers are created with @see link(), @see prop() + * and also via @LocalStorageLink and @LocalStorageProp state variable decorators. + * That means as long as their is a @Component instance that uses such decorated variable + * or a sync relationship with a SubscribedAbstractProperty variable the property can nit + * (and also should not!) be deleted from AppStorage. + * + * Same as @see LocalStorage.delete() + * + * @param propName + * @returns false if method failed + * + * @since 9 + */ + public static delete(key: string): boolean { + return AppStorage.getOrCreate().delete(key); + } + + /** + * @see delete + * @since 7 + * @deprecated + */ + public static Delete(key: string): boolean { + return AppStorage.getOrCreate().delete(key); + } + + /** + * Provide names of all properties in AppStorage + * same as ES6 Map.prototype.keys() + * + * Same as @see LocalStorage.keys() + * + * @returns return a Map Iterator + * + * @since 9 */ - public static StaticClear(): boolean { - return AppStorage.Clear(); - } + public static keys(): IterableIterator { + return AppStorage.getOrCreate().keys(); + } - /** - * not a public / sdk function - */ - public static AboutToBeDeleted(): void { - AppStorage.GetOrCreate().aboutToBeDeleted(); - } + /** + * @see keys + * @since 7 + * @deprecated + */ + public static Keys(): IterableIterator { + return AppStorage.getOrCreate().keys(); + } + /** + * Returns number of properties in AppStorage + * same as Map.prototype.size() + * + * Same as @see LocalStorage.size() + * + * @param propName + * @returns return number of properties + * + * @since 9 + */ + public static size(): number { + return AppStorage.getOrCreate().size(); + } - /** - * return number of subscribers to named property - * useful for debug purposes - * - * not a public / sdk function - */ - public static NumberOfSubscribersTo(propName: string): number | undefined { - return AppStorage.GetOrCreate().numberOfSubscrbersTo(propName); - } - - - /** - * Subscribe to value change notifications of named property - * Any object implementing ISinglePropertyChangeSubscriber interface - * and registerign itself to SubscriberManager can register - * Caution: do remember to unregister, otherwise the property will block - * cleanup, @see delete() and @see clear() - * - * Same as @see LocalStorage.subscribeToChangesOf() - * - * @param propName property in AppStorage to subscribe to - * @param subscriber object that implements ISinglePropertyChangeSubscriber interface - * @returns false if named property does not exist - * - * @since 7 - */ - public static SubscribeToChangesOf(propName: string, subscriber: ISinglePropertyChangeSubscriber): boolean { - return AppStorage.GetOrCreate().subscribeToChangesOf(propName, subscriber); - } + /** + * @see size + * @since 7 + * @deprecated + */ + public static Size(): number { + return AppStorage.getOrCreate().size(); + } + /** + * delete all properties from the AppStorage + * + * @see delete(), same as @see LocalStorage.clear() + * + * precondition is that there are no subscribers. + * method returns false and deletes no poperties if there is any property + * that still has subscribers + * + * @since 9 + */ + public static clear(): boolean { + return AppStorage.getOrCreate().clear(); + } - /** - * inverse of @see SubscribeToChangesOf, - * same as @see LocalStorage.subscribeToChangesOf() - * - * @param propName property in AppStorage to subscribe to - * @param subscriberId id of the subscrber passed to @see subscribeToChangesOf - * @returns false if named property does not exist - * - * @since 7 - */ - public static UnsubscribeFromChangesOf(propName: string, subscriberId: number): boolean { - return AppStorage.GetOrCreate().unsubscribeFromChangesOf(propName, subscriberId); - } + /** + * @see clear + * @since 7 + * @deprecated + */ + public static Clear(): boolean { + return AppStorage.getOrCreate().clear(); + } - /** - * Unimplemenrted, currently all properties of AppStorage are mutable. - * - * @since 7, depreciated - */ - public static IsMutable(key: string): boolean { - return true; - } + /** + * Same as @see clear(). + * + * @since 7, deprecated, used clear() instead! + * + */ + public static StaticClear(): boolean { + return AppStorage.clear(); + } - /** - * not a public / sdk function - */ + /** + * not a public / sdk function + */ + public static aboutToBeDeleted(): void { + AppStorage.getOrCreate().aboutToBeDeleted(); + } - public static __CreateSync(storagePropName: string, defaultValue: T, - factoryFunc: SynchedPropertyFactoryFunc): ObservedPropertyAbstract { - return AppStorage.GetOrCreate().__createSync(storagePropName, defaultValue, factoryFunc); - } - // instance functions below: - // Should all be protected, but TS lang does not allow access from static member to protected member + /** + * return number of subscribers to named property + * useful for debug purposes + * + * not a public / sdk function + */ + public static numberOfSubscribersTo(propName: string): number | undefined { + return AppStorage.getOrCreate().numberOfSubscrbersTo(propName); + } - private static Instance_: AppStorage = undefined; - /** - * not a public / sdk function - */ - private static GetOrCreate(): AppStorage { - if (!AppStorage.Instance_) { - stateMgmtConsole.warn("AppStorage instance missing. Use AppStorage.CreateInstance(initObj). Creating instance without any initialization."); - AppStorage.Instance_ = new AppStorage({}); + /** + * Subscribe to value change notifications of named property + * Any object implementing ISinglePropertyChangeSubscriber interface + * and registerign itself to SubscriberManager can register + * Caution: do remember to unregister, otherwise the property will block + * cleanup, @see delete() and @see clear() + * + * Same as @see LocalStorage.subscribeToChangesOf() + * + * @param propName property in AppStorage to subscribe to + * @param subscriber object that implements ISinglePropertyChangeSubscriber interface + * @returns false if named property does not exist + * + * @since 9 + */ + public static subscribeToChangesOf(propName: string, subscriber: ISinglePropertyChangeSubscriber): boolean { + return AppStorage.getOrCreate().subscribeToChangesOf(propName, subscriber); } - return AppStorage.Instance_; - } - /** singleton class, app can not create instances - * - * not a public / sdk function - */ - protected constructor(initializingProperties: Object) { - super(initializingProperties); - } + + /** + * @see subscribeToChangesOf + * @since 7 + * @deprecated + */ + public static SubscribeToChangesOf(propName: string, subscriber: ISinglePropertyChangeSubscriber): boolean { + return AppStorage.getOrCreate().subscribeToChangesOf(propName, subscriber); + } + + /** + * inverse of @see SubscribeToChangesOf, + * same as @see LocalStorage.subscribeToChangesOf() + * + * @param propName property in AppStorage to subscribe to + * @param subscriberId id of the subscrber passed to @see subscribeToChangesOf + * @returns false if named property does not exist + * + * @since 9 + */ + public static unsubscribeFromChangesOf(propName: string, subscriberId: number): boolean { + return AppStorage.getOrCreate().unsubscribeFromChangesOf(propName, subscriberId); + } + + /** + * @see unsubscribeFromChangesOf + * @since 7 + * @deprecated + */ + public static UnsubscribeFromChangesOf(propName: string, subscriberId: number): boolean { + return AppStorage.getOrCreate().unsubscribeFromChangesOf(propName, subscriberId); + } + + /** + * Unimplemented, currently all properties of AppStorage are mutable. + * + * @since 7, deprecated + */ + public static IsMutable(key: string): boolean { + return true; + } + + /** + * not a public / sdk function + */ + + public static __createSync(storagePropName: string, defaultValue: T, + factoryFunc: SynchedPropertyFactoryFunc): ObservedPropertyAbstract { + return AppStorage.getOrCreate().__createSync(storagePropName, defaultValue, factoryFunc); + } + + // instance functions below: + // Should all be protected, but TS lang does not allow access from static member to protected member + + private static instance_: AppStorage = undefined; + + /** + * not a public / sdk function + */ + private static getOrCreate(): AppStorage { + if (!AppStorage.instance_) { + stateMgmtConsole.warn("AppStorage instance missing. Use AppStorage.createInstance(initObj). Creating instance without any initialization."); + AppStorage.instance_ = new AppStorage({}); + } + return AppStorage.instance_; + } + + /** singleton class, app can not create instances + * + * not a public / sdk function + */ + protected constructor(initializingProperties: Object) { + super(initializingProperties); + } } diff --git a/frameworks/bridge/declarative_frontend/state_mgmt/src/lib/sdk/environment.ts b/frameworks/bridge/declarative_frontend/state_mgmt/src/lib/sdk/environment.ts index 84e56b0e39dea31f75c490b77373c4f38f0ad4ea..f2185147fcd28fbae31607e0112759f1eef39d9b 100644 --- a/frameworks/bridge/declarative_frontend/state_mgmt/src/lib/sdk/environment.ts +++ b/frameworks/bridge/declarative_frontend/state_mgmt/src/lib/sdk/environment.ts @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -21,57 +21,102 @@ */ class Environment { - private static Instance_: Environment = undefined; - private static EnvBackend_: IEnvironmentBackend; + private static instance_: Environment = undefined; + private static envBackend_: IEnvironmentBackend; private props_: Map>; - private static GetOrCreate(): Environment { - if (Environment.Instance_) { + private static getOrCreate(): Environment { + if (Environment.instance_) { // already initialized - return Environment.Instance_; + return Environment.instance_; } - Environment.Instance_ = new Environment(); - return Environment.Instance_; + Environment.instance_ = new Environment(); + return Environment.instance_; } + public static configureBackend(envBackend: IEnvironmentBackend): void { + Environment.envBackend_ = envBackend; + } + + /** + * @see configureBackend + * @deprecated + */ public static ConfigureBackend(envBackend: IEnvironmentBackend): void { - Environment.EnvBackend_ = envBackend; + Environment.envBackend_ = envBackend; } - public static AboutToBeDeleted(): void { - if (!Environment.Instance_) { + + public static aboutToBeDeleted(): void { + if (!Environment.instance_) { return; } - Environment.GetOrCreate().aboutToBeDeleted(); - Environment.Instance_ = undefined; + Environment.getOrCreate().aboutToBeDeleted(); + Environment.instance_ = undefined; + } + + /** + * @see aboutToBeDeleted + * @deprecated + */ + public static AboutToBeDeleted(): void { + Environment.aboutToBeDeleted(); + } + + public static envProp(key: string, value: S): boolean { + return Environment.getOrCreate().envProp(key, value); } + /** + * @see envProp + * @deprecated + */ public static EnvProp(key: string, value: S): boolean { - return Environment.GetOrCreate().envProp(key, value); + return Environment.getOrCreate().envProp(key, value); } + public static envProps(props: { + key: string, + defaultValue: any + }[] + ): void { + Environment.getOrCreate().envProps(props); + } + + /** + * @see envProps + * @deprecated + */ public static EnvProps(props: { key: string, defaultValue: any }[] ): void { - Environment.GetOrCreate().envProps(props); + Environment.getOrCreate().envProps(props); + } + + static keys(): Array { + return Environment.getOrCreate().keys(); } + /** + * @see keys + * @deprecated + */ static Keys(): Array { - return Environment.GetOrCreate().keys(); + return Environment.getOrCreate().keys(); } private constructor() { this.props_ = new Map>(); - Environment.EnvBackend_.onValueChanged(this.onValueChanged.bind(this)); + Environment.envBackend_.onValueChanged(this.onValueChanged.bind(this)); } private envProp(key: string, value: S): boolean { - let prop = AppStorage.Prop(key); + let prop = AppStorage.prop(key); if (prop) { stateMgmtConsole.warn(`Environment: envProp '${key}': Property already exists in AppStorage. Not using environment property.`); return false; @@ -79,27 +124,27 @@ class Environment { let tmp; switch(key) { case "accessibilityEnabled": - tmp = Environment.EnvBackend_ .getAccessibilityEnabled(); + tmp = Environment.envBackend_ .getAccessibilityEnabled(); break; case "colorMode": - tmp = Environment.EnvBackend_ .getColorMode(); + tmp = Environment.envBackend_ .getColorMode(); break; case "fontScale": - tmp = Environment.EnvBackend_ .getFontScale(); + tmp = Environment.envBackend_ .getFontScale(); break; case "fontWeightScale": - tmp = Environment.EnvBackend_ .getFontWeightScale().toFixed(2); + tmp = Environment.envBackend_ .getFontWeightScale().toFixed(2); break; case "layoutDirection": - tmp = Environment.EnvBackend_ .getLayoutDirection(); + tmp = Environment.envBackend_ .getLayoutDirection(); break; case "languageCode": - tmp = Environment.EnvBackend_ .getLanguageCode(); + tmp = Environment.envBackend_ .getLanguageCode(); break; default: tmp = value; } - prop = AppStorage.SetAndProp(key, tmp); + prop = AppStorage.setAndProp(key, tmp); this.props_.set(key, prop); stateMgmtConsole.debug(`Environment: envProp for '${key}' done.`); } @@ -128,7 +173,7 @@ class Environment { } onValueChanged(key: string, value: any): void { - let ok = AppStorage.Set(key, value); + let ok = AppStorage.set(key, value); if (ok) { stateMgmtConsole.debug(`Environment: onValueChanged: ${key} changed to ${value}`); } else { @@ -139,7 +184,7 @@ class Environment { aboutToBeDeleted() { this.props_.forEach((val, key, map) => { val.aboutToBeDeleted(); - AppStorage.Delete(key); + AppStorage.delete(key); }); } } diff --git a/frameworks/bridge/declarative_frontend/state_mgmt/src/lib/sdk/persistent_storage.ts b/frameworks/bridge/declarative_frontend/state_mgmt/src/lib/sdk/persistent_storage.ts index ac7e903c722a239a214b9eeb42044da155ea1301..a7d69a7130ce27ba2e8730aa97a06ebc840e677a 100644 --- a/frameworks/bridge/declarative_frontend/state_mgmt/src/lib/sdk/persistent_storage.ts +++ b/frameworks/bridge/declarative_frontend/state_mgmt/src/lib/sdk/persistent_storage.ts @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -22,8 +22,8 @@ */ class PersistentStorage implements IMultiPropertiesChangeSubscriber { - private static Storage_: IStorage; - private static Instance_: PersistentStorage = undefined; + private static storage_: IStorage; + private static instance_: PersistentStorage = undefined; private id_: number; private links_: Map>; @@ -36,40 +36,40 @@ class PersistentStorage implements IMultiPropertiesChangeSubscriber { * internal function, not part of the SDK * */ - public static ConfigureBackend(storage: IStorage): void { - PersistentStorage.Storage_ = storage; + public static configureBackend(storage: IStorage): void { + PersistentStorage.storage_ = storage; } /** * private, use static functions! */ - private static GetOrCreate(): PersistentStorage { - if (PersistentStorage.Instance_) { + private static getOrCreate(): PersistentStorage { + if (PersistentStorage.instance_) { // already initialized - return PersistentStorage.Instance_; + return PersistentStorage.instance_; } - PersistentStorage.Instance_ = new PersistentStorage(); - return PersistentStorage.Instance_; + PersistentStorage.instance_ = new PersistentStorage(); + return PersistentStorage.instance_; } /** * * internal function, not part of the SDK */ - public static AboutToBeDeleted(): void { - if (!PersistentStorage.Instance_) { + public static aboutToBeDeleted(): void { + if (!PersistentStorage.instance_) { return; } - PersistentStorage.GetOrCreate().aboutToBeDeleted(); - PersistentStorage.Instance_ = undefined; + PersistentStorage.getOrCreate().aboutToBeDeleted(); + PersistentStorage.instance_ = undefined; } /** * Add property 'key' to AppStorage properties whose current value will be - * persistemt. + * persistent. * If AppStorage does not include this property it will be added and initializes * with given value * @@ -79,35 +79,63 @@ class PersistentStorage implements IMultiPropertiesChangeSubscriber { * @param defaultValue If AppStorage does not include this property it will be initialized with this value * */ + public static persistProp(key: string, defaultValue: T): void { + PersistentStorage.getOrCreate().persistProp(key, defaultValue); + } + + /** + * @see persistProp + * @deprecated + */ public static PersistProp(key: string, defaultValue: T): void { - PersistentStorage.GetOrCreate().persistProp(key, defaultValue); + PersistentStorage.getOrCreate().persistProp(key, defaultValue); } + /** - * Reverse of @see PersistProp + * Reverse of @see persistProp * @param key no longer persist the property named key * * @since 9 */ + public static deleteProp(key: string): void { + PersistentStorage.getOrCreate().deleteProp(key); + } + + /** + * @see deleteProp + * @deprecated + */ public static DeleteProp(key: string): void { - PersistentStorage.GetOrCreate().deleteProp(key); + PersistentStorage.getOrCreate().deleteProp(key); } /** * Persist given AppStorage properties with given names. * If a property does not exist in AppStorage, add it and initialize it with given value - * works as @see PersistProp for multiple properties. + * works as @see persistProp for multiple properties. * * @param properties * * @since 9 * */ + public static persistProps(properties: { + key: string, + defaultValue: any + }[]): void { + PersistentStorage.getOrCreate().persistProps(properties); + } + + /** + * @see persistProps + * @deprecated + */ public static PersistProps(properties: { key: string, defaultValue: any }[]): void { - PersistentStorage.GetOrCreate().persistProps(properties); + PersistentStorage.getOrCreate().persistProps(properties); } /** @@ -116,9 +144,9 @@ class PersistentStorage implements IMultiPropertiesChangeSubscriber { * * @since 9 */ - public static Keys(): Array { + public static keys(): Array { let result = []; - const it = PersistentStorage.GetOrCreate().keys(); + const it = PersistentStorage.getOrCreate().keys(); let val = it.next(); while (!val.done) { @@ -129,6 +157,14 @@ class PersistentStorage implements IMultiPropertiesChangeSubscriber { return result; } + /** + * @see keys + * @deprecated + */ + public static Keys(): Array { + return PersistentStorage.keys(); + } + /** * This methid offers a way to force writing the property value with given * key to persistent storage. @@ -142,12 +178,24 @@ class PersistentStorage implements IMultiPropertiesChangeSubscriber { * @since 9 * */ - public static NotifyHasChanged(propName: string) { + public static notifyHasChanged(propName: string) { stateMgmtConsole.debug(`PersistentStorage: force writing '${propName}'- - '${PersistentStorage.GetOrCreate().links_.get(propName)}' to storage`); - PersistentStorage.Storage_.set(propName, - PersistentStorage.GetOrCreate().links_.get(propName).get()); -} + '${PersistentStorage.getOrCreate().links_.get(propName)}' to storage`); + PersistentStorage.storage_.set(propName, + PersistentStorage.getOrCreate().links_.get(propName).get()); + } + + /** + * @see notifyHasChanged + * @deprecated + */ + public static NotifyHasChanged(propName: string) { + stateMgmtConsole.debug(`PersistentStorage: force writing '${propName}'- + '${PersistentStorage.getOrCreate().links_.get(propName)}' to storage`); + PersistentStorage.storage_.set(propName, + PersistentStorage.getOrCreate().links_.get(propName).get()); + } + /** * all following methods are framework internal */ @@ -166,7 +214,7 @@ class PersistentStorage implements IMultiPropertiesChangeSubscriber { if (this.persistProp1(propName, defaultValue)) { // persist new prop stateMgmtConsole.debug(`PersistentStorage: writing '${propName}' - '${this.links_.get(propName)}' to storage`); - PersistentStorage.Storage_.set(propName, this.links_.get(propName).get()); + PersistentStorage.storage_.set(propName, this.links_.get(propName).get()); } } @@ -184,12 +232,12 @@ class PersistentStorage implements IMultiPropertiesChangeSubscriber { return false; } - let link = AppStorage.Link(propName, this); + let link = AppStorage.link(propName, this); if (link) { stateMgmtConsole.debug(`PersistentStorage: persistProp ${propName} in AppStorage, using that`); this.links_.set(propName, link); } else { - let newValue: T = PersistentStorage.Storage_.get(propName); + let newValue: T = PersistentStorage.storage_.get(propName); let returnValue: T; if (!newValue) { stateMgmtConsole.debug(`PersistentStorage: no entry for ${propName}, will initialize with default value`); @@ -198,7 +246,7 @@ class PersistentStorage implements IMultiPropertiesChangeSubscriber { else { returnValue = newValue; } - link = AppStorage.SetAndLink(propName, returnValue, this); + link = AppStorage.setAndLink(propName, returnValue, this); this.links_.set(propName, link); stateMgmtConsole.debug(`PersistentStorage: created new persistent prop for ${propName}`); } @@ -218,7 +266,7 @@ class PersistentStorage implements IMultiPropertiesChangeSubscriber { if (link) { link.aboutToBeDeleted(); this.links_.delete(propName); - PersistentStorage.Storage_.delete(propName); + PersistentStorage.storage_.delete(propName); stateMgmtConsole.debug(`PersistentStorage: deleteProp: no longer persisting '${propName}'.`); } else { stateMgmtConsole.warn(`PersistentStorage: '${propName}' is not a persisted property warning.`); @@ -228,7 +276,7 @@ class PersistentStorage implements IMultiPropertiesChangeSubscriber { private write(): void { this.links_.forEach((link, propName, map) => { stateMgmtConsole.debug(`PersistentStorage: writing ${propName} to storage`); - PersistentStorage.Storage_.set(propName, link.get()); + PersistentStorage.storage_.set(propName, link.get()); }); } @@ -247,7 +295,7 @@ class PersistentStorage implements IMultiPropertiesChangeSubscriber { this.links_.clear(); SubscriberManager.Delete(this.id__()); - PersistentStorage.Storage_.clear(); + PersistentStorage.storage_.clear(); } public id__(): number { diff --git a/frameworks/bridge/declarative_frontend/state_mgmt/src/utest/common/app_storage_array_test.ts b/frameworks/bridge/declarative_frontend/state_mgmt/src/utest/common/app_storage_array_test.ts index a2fd86c864a2ed58bb9390e680bacb739b0e7c3a..90e493e3c6aa40f36a6f0567a0710334b496b960 100644 --- a/frameworks/bridge/declarative_frontend/state_mgmt/src/utest/common/app_storage_array_test.ts +++ b/frameworks/bridge/declarative_frontend/state_mgmt/src/utest/common/app_storage_array_test.ts @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -20,7 +20,7 @@ const testAppStorageArray = tsuite("AppStorage Array", () => { private id_: number = SubscriberManager. MakeId(); constructor() { - AppStorage.SubscribeToChangesOf("arr", this); + AppStorage.subscribeToChangesOf("arr", this); SubscriberManager.Add(this); } @@ -33,7 +33,7 @@ const testAppStorageArray = tsuite("AppStorage Array", () => { // that the subscriber is about to be deleted // hence , unsubscribe aboutToBeDeleted(owningView?: IPropertySubscriber): void { - AppStorage.UnsubscribeFromChangesOf("arr", this.id__()); + AppStorage.unsubscribeFromChangesOf("arr", this.id__()); SubscriberManager.Delete(this.id__()); } @@ -105,22 +105,22 @@ const testAppStorageArray = tsuite("AppStorage Array", () => { tcase("create and read back", () => { let arr: number[] = [1, 2, 3, 4]; - AppStorage.SetOrCreate("arr", arr); + AppStorage.setOrCreate("arr", arr); - test("AppStrorage has initial one ObservedProperties", AppStorage.Size() == 1); - test("Initial array value readback.", AppStorage.Get("arr").toString() == arr.toString()); - test(`Initial array value readback, check Array.isArray`, Array.isArray(AppStorage.Get("arr"))); - test(`Initial array value readback, check instance of ObservedObject`, ObservedObject.IsObservedObject(AppStorage.Get("arr"))); + test("AppStrorage has initial one ObservedProperties", AppStorage.size() == 1); + test("Initial array value readback.", AppStorage.get("arr").toString() == arr.toString()); + test(`Initial array value readback, check Array.isArray`, Array.isArray(AppStorage.get("arr"))); + test(`Initial array value readback, check instance of ObservedObject`, ObservedObject.IsObservedObject(AppStorage.get("arr"))); }); tcase("push to array", () => { let arrSub = new ArrayChangeSubscriber(); let spyArrayChange = spyOn(arrSub, "hasChanged"); - AppStorage.Get("arr").push(5); - test("Changed array value readback", AppStorage.Get("arr").toString() == [1, 2, 3, 4, 5].toString()); + AppStorage.get("arr").push(5); + test("Changed array value readback", AppStorage.get("arr").toString() == [1, 2, 3, 4, 5].toString()); test(`hasChanged was called`, spyArrayChange.called); test(`hasChanged param is the correct changed array.`, spyArrayChange.args[0].toString() == [1, 2, 3, 4, 5].toString()); - test(`Initial array value readback, check instance of ObservedObject`, ObservedObject.IsObservedObject(AppStorage.Get("arr"))); + test(`Initial array value readback, check instance of ObservedObject`, ObservedObject.IsObservedObject(AppStorage.get("arr"))); arrSub.aboutToBeDeleted(); }); @@ -128,12 +128,12 @@ const testAppStorageArray = tsuite("AppStorage Array", () => { let arrSub = new ArrayChangeSubscriber(); let spyArrayChange = spyOn(arrSub, "hasChanged"); - AppStorage.Set("arr", [2, 3, 4]); + AppStorage.set("arr", [2, 3, 4]); - test("Changed array value readback", AppStorage.Get("arr").toString() == [2, 3, 4].toString()); + test("Changed array value readback", AppStorage.get("arr").toString() == [2, 3, 4].toString()); test(`hasChanged was called`, spyArrayChange.called); test(`hasChanged param is the correct changed array.`, spyArrayChange.args[0].toString() == [2, 3, 4].toString()); - test(`Initial array value readback, check instance of ObservedObject`, ObservedObject.IsObservedObject(AppStorage.Get("arr"))); + test(`Initial array value readback, check instance of ObservedObject`, ObservedObject.IsObservedObject(AppStorage.get("arr"))); arrSub.aboutToBeDeleted(); }); @@ -141,19 +141,19 @@ const testAppStorageArray = tsuite("AppStorage Array", () => { tcase("change property value gets observed #2", () => { let arrSub = new ArrayChangeSubscriber(); - AppStorage.Set("arr", [2, 3, 4]); + AppStorage.set("arr", [2, 3, 4]); let spyArrayChange = spyOn(arrSub, "hasChanged"); - AppStorage.Get("arr")[1] = 7; + AppStorage.get("arr")[1] = 7; - test("Changed array value readback", AppStorage.Get("arr").toString() == [2, 7, 4].toString()); + test("Changed array value readback", AppStorage.get("arr").toString() == [2, 7, 4].toString()); test(`hasChanged was called`, spyArrayChange.called); test(`hasChanged param is the correct changed array.`, spyArrayChange.args[0].toString() == [2, 7, 4].toString()); arrSub.aboutToBeDeleted(); }); tcase("ObservedObject Array proxying is transparent", () => { - AppStorage.Set("arr", [2, 3, 4]); - let link = AppStorage.Link("arr"); + AppStorage.set("arr", [2, 3, 4]); + let link = AppStorage.link("arr"); test("link readback value OK", link.get().toString() == [2, 3, 4].toString()); test("link readback value OK", link.get().length == 3); test("Array.isArray(link) OK", Array.isArray(link.get())); @@ -170,14 +170,14 @@ const testAppStorageArray = tsuite("AppStorage Array", () => { tcase("cleanup ok", () => { // manual cleanup to see everything works as expected - const deleteOk = AppStorage.Delete("arr"); + const deleteOk = AppStorage.delete("arr"); test(`Deletion of props form AppStrorage without isuses`, deleteOk); - test(`AppStrorage has ${AppStorage.Size()} ObservedProperties: >${Array.from(AppStorage.Keys())}<, should be none.`, AppStorage.Size() == 0); + test(`AppStrorage has ${AppStorage.size()} ObservedProperties: >${Array.from(AppStorage.keys())}<, should be none.`, AppStorage.size() == 0); test(`SubscriberManager num of subscribers us ${SubscriberManager.NumberOfSubscribers()} should be 0 .`, SubscriberManager.NumberOfSubscribers() == 0); // this will do nothing because manual cleanup was done already - AppStorage.AboutToBeDeleted(); + AppStorage.aboutToBeDeleted(); }); }); diff --git a/frameworks/bridge/declarative_frontend/state_mgmt/src/utest/common/app_storage_test.ts b/frameworks/bridge/declarative_frontend/state_mgmt/src/utest/common/app_storage_test.ts index f36bcb51e78d324a5fdc632d92471a72e73d13fe..41301602d7546fce8185e6b903d66c54d7256723 100644 --- a/frameworks/bridge/declarative_frontend/state_mgmt/src/utest/common/app_storage_test.ts +++ b/frameworks/bridge/declarative_frontend/state_mgmt/src/utest/common/app_storage_test.ts @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -16,56 +16,56 @@ const testAppStorage = tsuite("AppStorage", () => { tcase("size", () => { - AppStorage.CreateSingleton({say: "Hello", name: "Gudio"}); - test("AppStrorage has initial two ObservedProperties", AppStorage.Size() == 2); + AppStorage.createSingleton({say: "Hello", name: "Gudio"}); + test("AppStrorage has initial two ObservedProperties", AppStorage.size() == 2); }); tcase("AppStorage has self set value", () => { - test("added 'say' is in AppStrorage", AppStorage.Has("say")); + test("added 'say' is in AppStrorage", AppStorage.has("say")); }); tcase("AppStorage remembers self set value", () => { - test("added 'say' wrong value", AppStorage.Get("say") == "Hello"); - test("added 'name' wrong value", AppStorage.Get("name") == "Gudio"); + test("added 'say' wrong value", AppStorage.get("say") == "Hello"); + test("added 'name' wrong value", AppStorage.get("name") == "Gudio"); }); tcase("AppStorage remembers self set boolean value", () => { - AppStorage.SetOrCreate("true", true); - test("added 'true' wrong boolean value", AppStorage.Get("true")); + AppStorage.setOrCreate("true", true); + test("added 'true' wrong boolean value", AppStorage.get("true")); }); tcase("AppStorage remembers self set number value", () => { - AppStorage.SetOrCreate("favorite", 47); + AppStorage.setOrCreate("favorite", 47); - test("added 'favorite', has correct number value", AppStorage.Get("favorite") == 47); - test("added 'favorite' converted to string is '47'", AppStorage.Get("favorite") == "47"); + test("added 'favorite', has correct number value", AppStorage.get("favorite") == 47); + test("added 'favorite' converted to string is '47'", AppStorage.get("favorite") == "47"); }); - var link1: SubscribedAbstractProperty = AppStorage.Link("say"); - var link2: SubscribedAbstractProperty = AppStorage.Link("say"); + var link1: SubscribedAbstractProperty = AppStorage.link("say"); + var link2: SubscribedAbstractProperty = AppStorage.link("say"); tcase("AppStorage and link1 update from link1.set", () => { link1.set("Anton"); - test("AppStorage: 'say' expected updated value is `Anton`.", AppStorage.Get("say") == "Anton"); + test("AppStorage: 'say' expected updated value is `Anton`.", AppStorage.get("say") == "Anton"); test("SyncedPropertyTwoWay#1: 'say' expected updated value is `Anton`.", link2.get() == "Anton"); }); tcase("AppStorage and link2 update from link1.set", () => { link1.set("Hanna"); - test("AppStorage: 'say' expected updated value is `Hanna`.", AppStorage.Get("say") == "Hanna"); + test("AppStorage: 'say' expected updated value is `Hanna`.", AppStorage.get("say") == "Hanna"); test("SyncedPropertyTwoWay#2: 'say' expected updated value is `Hanna`.", link2.get() == "Hanna"); }); tcase("link1 and link2 update from AppStorage.set", () => { - AppStorage.Set("say", "Paul"); + AppStorage.set("say", "Paul"); test("SyncedPropertyTwoWay#1: 'say' expected updated value is `Paul`.", link1.get() == "Paul"); test("SyncedPropertyTwoWay#2: 'say' expected updated value is `Paul`.", link2.get() == "Paul"); }); - AppStorage.Set("say", "Guido"); - let prop = AppStorage.Prop("say"); + AppStorage.set("say", "Guido"); + let prop = AppStorage.prop("say"); tcase("prop.get", () => { test("prop value expected `Guido`.", prop.get() == "Guido"); @@ -76,18 +76,18 @@ const testAppStorage = tsuite("AppStorage", () => { prop.set("Hanna"); test("prop changed value expected `Hanna`.", prop.get() == "Hanna"); test("link1 unchanged value expected `Guido`.", link1.get() == "Guido"); - test("app unchanged value expected `Guido`.", AppStorage.Get("say") == "Guido"); + test("app unchanged value expected `Guido`.", AppStorage.get("say") == "Guido"); }) tcase("appstorage set changes prop values", () => { - AppStorage.Set("say", "Anton"); + AppStorage.set("say", "Anton"); test("prop changed value expected `Anton`.", prop.get() == "Anton"); }) tcase("unsubscribe proptoLink1, linkToLink2", () => { - const asSubscribers = AppStorage.NumberOfSubscribersTo("say"); + const asSubscribers = AppStorage.numberOfSubscribersTo("say"); link2.aboutToBeDeleted(); - test("link2 subscriber has been unsubscribed from as", AppStorage.NumberOfSubscribersTo("say") == asSubscribers - 1); + test("link2 subscriber has been unsubscribed from as", AppStorage.numberOfSubscribersTo("say") == asSubscribers - 1); }) class TestAClass { @@ -99,22 +99,22 @@ const testAppStorage = tsuite("AppStorage", () => { let objAClass2: TestAClass = { a: 101, b: 201 }; tcase("ObservedObject create, get, set", () => { - AppStorage.SetOrCreate("objAClass", objAClass1); - test("ObservedObject create, value read back prop 'a'", (AppStorage.Get("objAClass").a == 1 && AppStorage.Get("objAClass").b == 2)); + AppStorage.setOrCreate("objAClass", objAClass1); + test("ObservedObject create, value read back prop 'a'", (AppStorage.get("objAClass").a == 1 && AppStorage.get("objAClass").b == 2)); - AppStorage.Get("objAClass").a = 47; - test("ObservedObject property value change, value read back", AppStorage.Get("objAClass").a == 47); + AppStorage.get("objAClass").a = 47; + test("ObservedObject property value change, value read back", AppStorage.get("objAClass").a == 47); - AppStorage.Set("objAClass", objAClass2); + AppStorage.set("objAClass", objAClass2); test("ObservedProperty of type ObservedObject set new ObservedObject, value read back", - AppStorage.Get("objAClass").a == 101 && AppStorage.Get("objAClass").b == 201); + AppStorage.get("objAClass").a == 101 && AppStorage.get("objAClass").b == 201); - AppStorage.Get("objAClass").a = 102; + AppStorage.get("objAClass").a = 102; test("Followed by prop value change, value read back", - AppStorage.Get("objAClass").a == 102 && AppStorage.Get("objAClass").b == 201); + AppStorage.get("objAClass").a == 102 && AppStorage.get("objAClass").b == 201); }) - let linktoObsObj = AppStorage.Link("objAClass"); + let linktoObsObj = AppStorage.link("objAClass"); tcase("ObservedObject Link create, get, set", () => { @@ -123,7 +123,7 @@ const testAppStorage = tsuite("AppStorage", () => { linktoObsObj.get().b = 203; test("link to ObservedObject, set value, read back link value", linktoObsObj.get().b == 203); test("link to ObservedObject, set value, read back value from AppStorage", - AppStorage.Get("objAClass").b == 203); + AppStorage.get("objAClass").b == 203); }) tcase("ObservedObject Prop to Link create, get, set", () => { @@ -135,12 +135,11 @@ const testAppStorage = tsuite("AppStorage", () => { test("prop to link to ObservedObject, set value locally, read back prop value", propToLinktoObsObj.get().b == 204); test("prop to link to ObservedObject, set value locally, read back link value", linktoObsObj.get().b == 203); test("prop to link to ObservedObject, set value locally, read back value from AppStorage", - AppStorage.Get("objAClass").b == 203); + AppStorage.get("objAClass").b == 203); linktoObsObj.aboutToBeDeleted(); propToLinktoObsObj.aboutToBeDeleted(); }) - - let proptoObsObj = AppStorage.Prop("objAClass"); + let proptoObsObj = AppStorage.prop("objAClass"); tcase("ObservedObject Prop create, get, set", () => { @@ -149,11 +148,11 @@ const testAppStorage = tsuite("AppStorage", () => { proptoObsObj.get().b = 201; test("prop to ObservedObject, set value locally, read back prop value", proptoObsObj.get().b == 201); test("prop to ObservedObject, set value locally, read back original prop value from AppStorage", - AppStorage.Get("objAClass").b == 203); + AppStorage.get("objAClass").b == 203); - AppStorage.Set("objAClass", { a: 42, b: 84 }); + AppStorage.set("objAClass", { a: 42, b: 84 }); test("prop to ObservedObject, set value to AppStorage, read back from AppStorage", - AppStorage.Get("objAClass").b == 84); + AppStorage.get("objAClass").b == 84); test("prop to ObservedObject, set value to AppStorage, read back from prop", proptoObsObj.get().b == 84); }) @@ -166,11 +165,11 @@ const testAppStorage = tsuite("AppStorage", () => { test("prop to prop to ObservedObject, set value locally, read back prop value", propToPropObsObj.get().a == 201); test("prop to prop to ObservedObject, set value locally, read back value from parent prop", proptoObsObj.get().a == 42); test("prop to prop to ObservedObject, set value locally, read back original prop value from AppStorage", - AppStorage.Get("objAClass").a == 42); + AppStorage.get("objAClass").a == 42); - AppStorage.Set("objAClass", { a: 421, b: 842 }); + AppStorage.set("objAClass", { a: 421, b: 842 }); test("prop to prop to ObservedObject, set value to AppStorage, read back from AppStorage", - AppStorage.Get("objAClass").b == 842); + AppStorage.get("objAClass").b == 842); test("prop to prop toObservedObject, set value to AppStorage, read back from prop", propToPropObsObj.get().b == 842); test("prop to prop toObservedObject, set value to AppStorage, read back from parent prop", proptoObsObj.get().b == 842); @@ -185,11 +184,11 @@ const testAppStorage = tsuite("AppStorage", () => { proptoObsObj.get().b = 201; test("prop to ObservedObject, set value locally, read back prop value", proptoObsObj.get().b == 201); test("prop to ObservedObject, set value locally, read back original prop value from AppStorage", - AppStorage.Get("objAClass").b == 203); + AppStorage.get("objAClass").b == 203); - AppStorage.Set("objAClass", { a: 42, b: 84 }); + AppStorage.set("objAClass", { a: 42, b: 84 }); test("prop to ObservedObject, set value to AppStorage, read back from AppStorage", - AppStorage.Get("objAClass").b == 84); + AppStorage.get("objAClass").b == 84); test("prop to ObservedObject, set value to AppStorage, read back from prop", proptoObsObj.get().b == 84); }) @@ -202,11 +201,11 @@ const testAppStorage = tsuite("AppStorage", () => { test("prop to prop to ObservedObject, set value locally, read back prop value", propToPropObsObj.get().a == 201); test("prop to prop to ObservedObject, set value locally, read back value from parent prop", proptoObsObj.get().a == 42); test("prop to prop to ObservedObject, set value locally, read back original prop value from AppStorage", - AppStorage.Get("objAClass").a == 42); + AppStorage.get("objAClass").a == 42); AppStorage.Set("objAClass", { a: 421, b: 842 }); test("prop to prop to ObservedObject, set value to AppStorage, read back from AppStorage", - AppStorage.Get("objAClass").b == 842); + AppStorage.get("objAClass").b == 842); test("prop to prop toObservedObject, set value to AppStorage, read back from prop", propToPropObsObj.get().b == 842); test("prop to prop toObservedObject, set value to AppStorage, read back from parent prop", proptoObsObj.get().b == 842); @@ -219,13 +218,13 @@ const testAppStorage = tsuite("AppStorage", () => { prop.aboutToBeDeleted(); // note link2 and linktoLink2 have been deleted already earlier in this test suite! - const deleteOk = AppStorage.Delete("name") && AppStorage.Delete("say") && AppStorage.Delete("true") && AppStorage.Delete("favorite") && AppStorage.Delete("objAClass"); + const deleteOk = AppStorage.delete("name") && AppStorage.delete("say") && AppStorage.delete("true") && AppStorage.delete("favorite") && AppStorage.delete("objAClass"); test(`Deletion of props form AppStrorage without isuses`, deleteOk) // test that manual cleanup has been complete, before calling AppStorage.NboutToBeDeleted(); - test(`AppStrorage has ${AppStorage.Size()} ObservedProperties: >${Array.from(AppStorage.Keys())}<, should be none.`, AppStorage.Size() == 0); + test(`AppStrorage has ${AppStorage.size()} ObservedProperties: >${Array.from(AppStorage.keys())}<, should be none.`, AppStorage.size() == 0); - AppStorage.AboutToBeDeleted(); + AppStorage.aboutToBeDeleted(); test(`SubscriberManager num of subscribers is ${SubscriberManager.NumberOfSubscribers()} should be 0 .`, SubscriberManager.NumberOfSubscribers() == 0); diff --git a/frameworks/bridge/declarative_frontend/state_mgmt/src/utest/common/environment_test.ts b/frameworks/bridge/declarative_frontend/state_mgmt/src/utest/common/environment_test.ts index 84846502945d28dd69ec07b41e52176ee137f6ea..e528f0d6a444ec89628ce7a704b6765aceea9409 100644 --- a/frameworks/bridge/declarative_frontend/state_mgmt/src/utest/common/environment_test.ts +++ b/frameworks/bridge/declarative_frontend/state_mgmt/src/utest/common/environment_test.ts @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -25,19 +25,19 @@ const testEnvironment = tsuite("Environment", () => { ]; tcase("Initialization", () => { - Environment.ConfigureBackend(mockEnv); + Environment.configureBackend(mockEnv); test("Environment initialized", true); }); tcase("Injecting values", () => { - Environment.EnvProps(envProps); + Environment.envProps(envProps); }); tcase("Get all value keys", () => { - const keys = Environment.Keys(); + const keys = Environment.keys(); console.debug("Environment variables:"); for (let i in keys) { - console.debug(`${keys[i]} - strigified value: ${JSON.stringify(AppStorage.Get(keys[i]))}`); + console.debug(`${keys[i]} - strigified value: ${JSON.stringify(AppStorage.get(keys[i]))}`); } test("Environment number of keys returned corresponds with number of values registered", keys.length == envProps.length); @@ -45,21 +45,21 @@ const testEnvironment = tsuite("Environment", () => { tcase("Value retrieval", () => { // the native backend treats bool as string - test("Environment value 'accessibilityEnabled' correct", AppStorage.Get("accessibilityEnabled") == "false"); - test("Environment value 'languageCode' correct", AppStorage.Get("languageCode") == "cn"); + test("Environment value 'accessibilityEnabled' correct", AppStorage.get("accessibilityEnabled") == "false"); + test("Environment value 'languageCode' correct", AppStorage.get("languageCode") == "cn"); }); tcase("Value changes from backend", () => { mockEnv.simulateChange("accessibilityEnabled", true); mockEnv.simulateChange("languageCode", "en"); - test("Environment value 'languageCode' after backend change", AppStorage.Get("languageCode") == "en"); - test("Environment value 'accessibilityEnabled' after backend change", AppStorage.Get("accessibilityEnabled") === true); + test("Environment value 'languageCode' after backend change", AppStorage.get("languageCode") == "en"); + test("Environment value 'accessibilityEnabled' after backend change", AppStorage.get("accessibilityEnabled") === true); test("Environment value change simulation ", true); }); tcase("Teardown", () => { - Environment.AboutToBeDeleted(); + Environment.aboutToBeDeleted(); test("Environment instance destroyed", true); }); }); diff --git a/frameworks/bridge/declarative_frontend/state_mgmt/src/utest/common/persistent_storage_test.ts b/frameworks/bridge/declarative_frontend/state_mgmt/src/utest/common/persistent_storage_test.ts index e083d26dc448edb2a1573191fc980c207696d818..c85c2627c5f2503a94b3ea0da6be111e82dd9936 100644 --- a/frameworks/bridge/declarative_frontend/state_mgmt/src/utest/common/persistent_storage_test.ts +++ b/frameworks/bridge/declarative_frontend/state_mgmt/src/utest/common/persistent_storage_test.ts @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -15,20 +15,20 @@ const testPersistentStorage = tsuite("PersistentStorage", () => { let ms = new MockStorage("./src/utest/resources/test.db"); - PersistentStorage.ConfigureBackend(ms); + PersistentStorage.configureBackend(ms); tcase("persisting existing values in AppStorage", () => { - AppStorage.SetOrCreate("existingPropToPersist", 123); - PersistentStorage.PersistProp("existingPropToPersist", 456); + AppStorage.setOrCreate("existingPropToPersist", 123); + PersistentStorage.persistProp("existingPropToPersist", 456); - test("PersistentStorage 'existingPropToPersist' value retrieved from AppStorage correct", AppStorage.Get("existingPropToPersist") == 123); + test("PersistentStorage 'existingPropToPersist' value retrieved from AppStorage correct", AppStorage.get("existingPropToPersist") == 123); test("PersistentStorage 'existingPropToPersist' value retrieved from MockStorage correct", ms.get("existingPropToPersist") == 123); }); tcase("retrieval of values", () => { - AppStorage.SetOrCreate("persistentSay", "Terve"); - AppStorage.SetOrCreate("persistentSubject", "Maailma"); + AppStorage.setOrCreate("persistentSay", "Terve"); + AppStorage.setOrCreate("persistentSubject", "Maailma"); - PersistentStorage.PersistProps([{ + PersistentStorage.persistProps([{ key: "persistentSay", defaultValue: "Terve" }, { @@ -36,55 +36,55 @@ const testPersistentStorage = tsuite("PersistentStorage", () => { defaultValue: "Maailma" }]); - test(`PersistentStorage 'persistentSay' value retrieved from AppStorage correct`, AppStorage.Get("persistentSay") === "Terve"); - test("PersistentStorage 'persistentSubject' value retrieved from AppStorage correct", AppStorage.Get("persistentSubject") == "Maailma"); + test(`PersistentStorage 'persistentSay' value retrieved from AppStorage correct`, AppStorage.get("persistentSay") === "Terve"); + test("PersistentStorage 'persistentSubject' value retrieved from AppStorage correct", AppStorage.get("persistentSubject") == "Maailma"); }); tcase("writing values to IStorage via PersistentStorage", () => { - PersistentStorage.PersistProps([{ + PersistentStorage.persistProps([{ key: "writeToDb", defaultValue: "" }, { key: "numberToDb", defaultValue: 10 }]); - AppStorage.Set("writeToDb", "test"); - AppStorage.Set("numberToDb", 42); - test("PersistentStorage 'persistentSay' value retrieved from AppStorage correct", AppStorage.Get("persistentSay") == "Terve"); - test("PersistentStorage 'persistentSubject' value retrieved from AppStorage correct", AppStorage.Get("persistentSubject") == "Maailma"); - test("PersistentStorage 'writeToDb' value retrieved from AppStorage correct", AppStorage.Get("writeToDb") == "test"); - test("PersistentStorage 'numberToDb' value retrieved from AppStorage correct", AppStorage.Get("numberToDb") == 42); + AppStorage.set("writeToDb", "test"); + AppStorage.set("numberToDb", 42); + test("PersistentStorage 'persistentSay' value retrieved from AppStorage correct", AppStorage.get("persistentSay") == "Terve"); + test("PersistentStorage 'persistentSubject' value retrieved from AppStorage correct", AppStorage.get("persistentSubject") == "Maailma"); + test("PersistentStorage 'writeToDb' value retrieved from AppStorage correct", AppStorage.get("writeToDb") == "test"); + test("PersistentStorage 'numberToDb' value retrieved from AppStorage correct", AppStorage.get("numberToDb") == 42); test("PersistentStorage 'writeToDb' value retrieved from MockStorage correct", ms.get("writeToDb") == "test"); test("PersistentStorage 'numberToDb' value retrieved from MockStorage correct", ms.get("numberToDb") == 42); }); tcase("deleting values from IStorage via PersistentStorage", () => { - PersistentStorage.DeleteProp("writeToDb"); - PersistentStorage.DeleteProp("numberToDb"); - AppStorage.Delete("writeToDb"); - AppStorage.Delete("numberToDb"); + PersistentStorage.deleteProp("writeToDb"); + PersistentStorage.deleteProp("numberToDb"); + AppStorage.delete("writeToDb"); + AppStorage.delete("numberToDb"); test("MockStorage 'writeToDb' value deleted", ms.get("writeToDb") == undefined); test("MockStorage 'numberToDb' value deleted", ms.get("numberToDb") == undefined); }); tcase("Persisting new property that does not exist in db", () => { - PersistentStorage.PersistProp("newProp", "new property value"); + PersistentStorage.persistProp("newProp", "new property value"); - test("PersistentStorage 'newProp' value retrieved from AppStorage correct", AppStorage.Get("newProp") == "new property value"); + test("PersistentStorage 'newProp' value retrieved from AppStorage correct", AppStorage.get("newProp") == "new property value"); test("MockStorage 'newProp' value retrieved from MockStorage correct", ms.get("newProp") == "new property value"); }); tcase("keys retrieval", () => { - const keys = PersistentStorage.Keys(); + const keys = PersistentStorage.keys(); for (var i in keys) { console.debug(`${keys[i]}`); } }); tcase("teardown", () => { - PersistentStorage.AboutToBeDeleted(); - const deleteOk = AppStorage.Delete("persistentSay") && AppStorage.Delete("persistentSubject") && AppStorage.Delete("newProp") && AppStorage.Delete("existingPropToPersist"); + PersistentStorage.aboutToBeDeleted(); + const deleteOk = AppStorage.delete("persistentSay") && AppStorage.delete("persistentSubject") && AppStorage.delete("newProp") && AppStorage.delete("existingPropToPersist"); SubscriberManager.DumpSubscriberInfo(); diff --git a/frameworks/bridge/declarative_frontend/state_mgmt/src/utest/partial_update/viewpu_appstorage_test.ts b/frameworks/bridge/declarative_frontend/state_mgmt/src/utest/partial_update/viewpu_appstorage_test.ts index 99847a9e999960f2925880cd54a78d030f31350e..b841ee42a49e43562720487bd516b648bdf4d7e4 100644 --- a/frameworks/bridge/declarative_frontend/state_mgmt/src/utest/partial_update/viewpu_appstorage_test.ts +++ b/frameworks/bridge/declarative_frontend/state_mgmt/src/utest/partial_update/viewpu_appstorage_test.ts @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -48,19 +48,19 @@ const testViewAppStorage = tsuite("@StorageLink - AppStorge", () => { /* @StorageLink(moveDistance) storeProp:number= 0; */ let __storeProp: SubscribedAbstractProperty = - AppStorage.SetAndLink('storeProp', /* default value */ 7, /* subscriber */ storeView, /* var name in View */ "viewVar"); + AppStorage.setAndLink('storeProp', /* default value */ 7, /* subscriber */ storeView, /* var name in View */ "viewVar"); tcase("read back", () => { - test("readback from AppStorage", AppStorage.Get("storeProp") == 7); + test("readback from AppStorage", AppStorage.get("storeProp") == 7); test("readback from view variable", __storeProp.get() == 7); }); tcase("modify via AppStore", () => { let spy = spyOn(storeView, "propertyHasChanged"); - AppStorage.Set("storeProp", 47); + AppStorage.set("storeProp", 47); - test("readback from AppStorage", AppStorage.Get("storeProp") == 47); + test("readback from AppStorage", AppStorage.get("storeProp") == 47); test("readback from view variable", __storeProp.get() == 47); test("View.propertyHasChanged has been called", spy.called && spy.args[0] == "viewVar"); }); @@ -68,7 +68,7 @@ const testViewAppStorage = tsuite("@StorageLink - AppStorge", () => { tcase("modify via @StorageLink", () => { let spy2 = spyOn(storeView, "propertyHasChanged"); __storeProp.set(101); - test("readback from AppStorage", AppStorage.Get("storeProp") == 101); + test("readback from AppStorage", AppStorage.get("storeProp") == 101); test("readback from view variable", __storeProp.get() == 101); test("View.propertyHasChanged has been called", spy2.called && spy2.args[0] == "viewVar"); });