1/* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16interface IPropertySubscriber { 17 id(): number; 18 aboutToBeDeleted(owningView?: IPropertySubscriber): void; 19} 20 21interface ISinglePropertyChangeSubscriber<T> extends IPropertySubscriber { 22 hasChanged(newValue: T): void; 23} 24 25declare abstract class SubscribedAbstractProperty<T> { 26 protected subscribers_: Set<number>; 27 private id_; 28 private info_?; 29 constructor(subscribeMe?: IPropertySubscriber, info?: string); 30 id(): number; 31 info(): string; 32 abstract get(): T; 33 abstract set(newValue: T): void; 34 createTwoWaySync(subscribeMe?: IPropertySubscriber, info?: string): SyncedPropertyTwoWay<T>; 35 createOneWaySync(subscribeMe?: IPropertySubscriber, info?: string): SyncedPropertyOneWay<T>; 36 unlinkSuscriber(subscriberId: number): void; 37 protected notifyHasChanged(newValue: T): void; 38 protected notifyPropertyRead(): void; 39 numberOfSubscrbers(): number; 40} 41 42declare class SyncedPropertyTwoWay<T> extends SubscribedAbstractProperty<T> implements ISinglePropertyChangeSubscriber<T> { 43 private source_; 44 constructor(source: SubscribedAbstractProperty<T>, subscribeMe?: IPropertySubscriber, info?: string); 45 aboutToBeDeleted(unsubscribeMe?: IPropertySubscriber): void; 46 hasChanged(newValue: T): void; 47 get(): T; 48 set(newValue: T): void; 49} 50 51declare class SyncedPropertyOneWay<T> extends SubscribedAbstractProperty<T> implements ISinglePropertyChangeSubscriber<T> { 52 private wrappedValue_; 53 private source_; 54 constructor(source: SubscribedAbstractProperty<T>, subscribeMe?: IPropertySubscriber, info?: string); 55 aboutToBeDeleted(unsubscribeMe?: IPropertySubscriber): void; 56 hasChanged(newValue: T): void; 57 get(): T; 58 set(newValue: T): void; 59} 60 61export declare class AppStorage { 62 static Link<T>(propName: string): any; 63 static SetAndLink<T>(propName: string, defaultValue: T): SubscribedAbstractProperty<T>; 64 static Prop<S>(propName: string): any; 65 static SetAndProp<S>(propName: string, defaultValue: S): SubscribedAbstractProperty<S>; 66 static Has(propName: string): boolean; 67 static Get<T>(propName: string): T | undefined; 68 static Set<T>(propName: string, newValue: T): boolean; 69 static SetOrCreate<T>(propName: string, newValue: T): void; 70 static Delete(propName: string): boolean; 71 static Keys(): IterableIterator<string>; 72 static staticClear(): boolean; 73 static IsMutable(propName: string): boolean; 74 static Size(): number; 75} 76 77export declare class Environment { 78 constructor(); 79 static EnvProp<S>(key: string, value: S): boolean; 80 static EnvProps(props: { 81 key: string; 82 defaultValue: any; 83 }[]): void; 84 static Keys(): Array<string>; 85} 86 87export declare enum ColorMode { 88 LIGHT = 0, 89 DARK, 90} 91 92export declare enum LayoutDirection { 93 LTR = 0, 94 RTL, 95} 96 97export declare class PersistentStorage { 98 constructor(appStorage: AppStorage, storage: Storage); 99 static PersistProp<T>(key: string, defaultValue: T): void; 100 static DeleteProp(key: string): void; 101 static PersistProps(properties: { 102 key: string; 103 defaultValue: any; 104 }[]): void; 105 static Keys(): Array<string>; 106} 107 108export declare class Storage { 109 constructor(needCrossThread?: boolean, file?: string); 110 get(key: string): string | undefined; 111 set(key: string, val: any): void; 112 clear(): void; 113 delete(key: string): void; 114} 115 116export declare abstract class SubscribaleAbstract { 117 private owningProperties_: Set<number>; 118 constructor(); 119 protected notifyPropertyHasChanged(propName: string, newValue: any): void; 120 public addOwningProperty(subscriber: IPropertySubscriber): void; 121 public removeOwningProperty(property: IPropertySubscriber): void; 122 public removeOwningPropertyById(subscriberId: number): void; 123} 124 125export declare const appStorage: AppStorage; 126