1# State Management with Application-level Variables (System API) 2 3 4The state management module provides data storage, persistent data management, UIAbility data storage, and environment state required by applications. 5 6 7>**NOTE** 8> 9>The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. 10> 11>This topic describes only the system APIs provided by the module. For details about its public APIs, see [State Management with Application-level Variables](./ts-state-management.md). 12 13## SubscribedAbstractProperty\<T\> 14 15**Widget capability**: This API can be used in ArkTS widgets since API version 9. 16 17**Atomic service API**: This API can be used in atomic services since API version 11. 18 19**System capability**: SystemCapability.ArkUI.ArkUI.Full 20 21### subscribers\_ 22 23protected subscribers_: Set\<number\>; 24 25A set of subscribers. 26 27**System capability**: SystemCapability.ArkUI.ArkUI.Full 28 29**Return value** 30 31|Type |Description | 32|-----------|--------------| 33|Set\<number\> |A set of subscribers.| 34 35### id\_ 36 37private id_; 38 39Private member variable ID. 40 41**System capability**: SystemCapability.ArkUI.ArkUI.Full 42 43### info\_ 44 45private info\_\?; 46 47Variable information. 48 49**System capability**: SystemCapability.ArkUI.ArkUI.Full 50 51### constructor 52 53constructor(subscribeMe?: IPropertySubscriber,info?: string,); 54 55Constructor. 56 57**System capability**: SystemCapability.ArkUI.ArkUI.Full 58 59**Parameters** 60 61|Name |Type |Mandatory |Description | 62|---------|-----------|------------|--------------| 63|subscribeMe |[IPropertySubscriber](#ipropertysubscriber) |No |Variable properties. | 64|info |string |No |Variable information. | 65 66### id 67 68id(): number; 69 70Obtains the ID. 71 72**System capability**: SystemCapability.ArkUI.ArkUI.Full 73 74**Return value** 75 76|Type |Description | 77|-----------|--------------| 78|number |Obtained ID.| 79 80### createTwoWaySync 81 82createTwoWaySync(subscribeMe?: IPropertySubscriber, info?: string): SyncedPropertyTwoWay\<T\>; 83 84Creates two-way synchronization. 85 86**System capability**: SystemCapability.ArkUI.ArkUI.Full 87 88**Parameters** 89 90|Name |Type |Mandatory |Description | 91|---------|-----------|------------|--------------| 92|subscribeMe |[IPropertySubscriber](#ipropertysubscriber) |No |Variable properties. | 93|info |string |No |Variable information. | 94 95**Return value** 96 97|Type |Description | 98|-----------|--------------| 99|[SyncedPropertyTwoWay\<T\>](#syncedpropertytwowayt) |Two-way synchronized property.| 100 101### createOneWaySync 102 103createOneWaySync(subscribeMe?: IPropertySubscriber, info?: string): SyncedPropertyOneWay\<T\>; 104 105Creates one-way synchronization. 106 107**System capability**: SystemCapability.ArkUI.ArkUI.Full 108 109**Parameters** 110 111|Name |Type |Mandatory |Description | 112|---------|-----------|------------|--------------| 113|subscribeMe |[IPropertySubscriber](#ipropertysubscriber) |No |Variable properties. | 114|info |string |No |Variable information. | 115 116**Return value** 117 118|Type |Description | 119|-----------|--------------| 120|[SyncedPropertyOneWay\<T\>](#syncedpropertytwowayt) |One-way synchronized property.| 121 122### unlinkSuscriber 123 124unlinkSuscriber(subscriberId: number): void; 125 126Removes a subscriber. 127 128**System capability**: SystemCapability.ArkUI.ArkUI.Full 129 130**Parameters** 131 132|Name |Type |Mandatory |Description | 133|---------|-----------|------------|--------------| 134|subscriberId |number |Yes |ID of the subscriber to remove. | 135 136### notifyHasChanged 137 138protected notifyHasChanged(newValue: T): void; 139 140Notifies subscribers that the value has changed. 141 142**System capability**: SystemCapability.ArkUI.ArkUI.Full 143 144**Parameters** 145 146|Name |Type |Mandatory |Description | 147|---------|-----------|------------|--------------| 148|newValue |T |Yes |New value after the change. | 149 150### notifyPropertyRead 151 152protected notifyPropertyRead(): void; 153 154Notifies subscribers that the property has been read. 155 156**System capability**: SystemCapability.ArkUI.ArkUI.Full 157 158### numberOfSubscrbers 159 160numberOfSubscrbers(): number; 161 162Obtains the number of subscribers. 163 164**System capability**: SystemCapability.ArkUI.ArkUI.Full 165 166**Return value** 167 168|Type |Description | 169|-----------|--------------| 170|number |Number of subscribers.| 171 172## IPropertySubscriber 173 174**System capability**: SystemCapability.ArkUI.ArkUI.Full 175 176### id 177 178id(): number; 179 180Obtains the ID. 181 182**System capability**: SystemCapability.ArkUI.ArkUI.Full 183 184**Return value** 185 186|Type |Description | 187|-----------|--------------| 188|number |Variable ID obtained.| 189 190### aboutToBeDeleted 191 192aboutToBeDeleted(owningView?: IPropertySubscriber): void; 193 194Called when the object is about to be destroyed. 195 196**System capability**: SystemCapability.ArkUI.ArkUI.Full 197 198**Parameters** 199 200|Name |Type |Mandatory |Description | 201|---------|-----------|------------|--------------| 202|owningView |[IPropertySubscriber](#ipropertysubscriber) |No |Component that owns the current property. | 203 204## SyncedPropertyTwoWay\<T\> 205 206Inherits from [SubscribedAbstractProperty\<T\>](#subscribedabstractpropertyt). Represents a property with two-way synchronization. 207 208**System capability**: SystemCapability.ArkUI.ArkUI.Full 209 210### source\_ 211 212private source_; 213 214Data source for the two-way synchronized property. 215 216**System capability**: SystemCapability.ArkUI.ArkUI.Full 217 218### constructor 219 220constructor(source: SubscribedAbstractProperty\<T\>, subscribeMe?: IPropertySubscriber, info?: string); 221 222Constructor. 223 224**System capability**: SystemCapability.ArkUI.ArkUI.Full 225 226**Parameters** 227 228|Name |Type |Mandatory |Description | 229|---------|-----------|------------|--------------| 230|source |[SubscribedAbstractProperty\<T\>](#subscribedabstractpropertyt) |Yes |Data source for the two-way synchronized property. | 231|subscribeMe |[IPropertySubscriber](#ipropertysubscriber) |No |Subscriber. | 232|info |string |No |Additional information about the subscriber. | 233 234### aboutToBeDeleted 235 236aboutToBeDeleted(unsubscribeMe?: IPropertySubscriber): void; 237 238Called when the object is about to be destroyed. 239 240**System capability**: SystemCapability.ArkUI.ArkUI.Full 241 242**Parameters** 243 244|Name |Type |Mandatory |Description | 245|---------|-----------|------------|--------------| 246|unsubscribeMe |[IPropertySubscriber](#ipropertysubscriber) |No |Subscriber to remove. | 247 248### hasChanged 249 250hasChanged(newValue: T): void; 251 252Notifies subscribers that the property value has changed. 253 254**System capability**: SystemCapability.ArkUI.ArkUI.Full 255 256**Parameters** 257 258|Name |Type |Mandatory |Description | 259|---------|-----------|------------|--------------| 260|newValue |T |Yes |New value of the property. | 261 262### get 263 264get(): T; 265 266Obtains the current value of the property. 267 268**System capability**: SystemCapability.ArkUI.ArkUI.Full 269 270**Return value** 271 272|Type |Description | 273|------|------------| 274|T |Current value of the property. | 275 276### set 277 278set(newValue: T): void; 279 280Sets a new value for the property. 281 282**System capability**: SystemCapability.ArkUI.ArkUI.Full 283 284**Parameters** 285 286|Name |Type |Mandatory |Description | 287|---------|-----------|------------|--------------| 288|newValue |T |Yes |New value to set for the property. | 289 290## SyncedPropertyOneWay\<T\> 291 292Inherits from [SubscribedAbstractProperty\<T\>](#subscribedabstractpropertyt). Represents a property with one-way synchronization. 293 294**System capability**: SystemCapability.ArkUI.ArkUI.Full 295 296### wrappedValue\_ 297 298private wrappedValue_; 299 300Value used for one-way binding. 301 302**System capability**: SystemCapability.ArkUI.ArkUI.Full 303 304### source\_ 305 306private source_; 307 308Data source for the one-way synchronized property. 309 310**System capability**: SystemCapability.ArkUI.ArkUI.Full 311 312### constructor 313 314constructor(source: SubscribedAbstractProperty\<T\>, subscribeMe?: IPropertySubscriber, info?: string); 315 316Constructor. 317 318**System capability**: SystemCapability.ArkUI.ArkUI.Full 319 320**Parameters** 321 322|Name |Type |Mandatory |Description | 323|---------|-----------|------------|--------------| 324|source |[SubscribedAbstractProperty\<T\>](#subscribedabstractpropertyt) |Yes |Data source for the one-way synchronized property. | 325|subscribeMe |[IPropertySubscriber](#ipropertysubscriber) |No |Subscriber. | 326|info |string |No |Additional information of the subscriber. | 327 328### aboutToBeDeleted 329 330aboutToBeDeleted(unsubscribeMe?: IPropertySubscriber): void; 331 332Called when the object is about to be destroyed. 333 334**System capability**: SystemCapability.ArkUI.ArkUI.Full 335 336**Parameters** 337 338|Name |Type |Mandatory |Description | 339|---------|-----------|------------|--------------| 340|unsubscribeMe |[IPropertySubscriber](#ipropertysubscriber) |No |Subscriber to remove. | 341 342### hasChanged 343 344hasChanged(newValue: T): void; 345 346Notifies subscribers that the property value has changed. 347 348**System capability**: SystemCapability.ArkUI.ArkUI.Full 349 350**Parameters** 351 352|Name |Type |Mandatory |Description | 353|---------|-----------|------------|--------------| 354|newValue |T |Yes |New value of the property. | 355 356### get 357 358get(): T; 359 360Obtains the current value of the property. 361 362**System capability**: SystemCapability.ArkUI.ArkUI.Full 363 364**Return value** 365 366|Type |Description | 367|------|------------| 368|T |Current value of the property. | 369 370### set 371 372set(newValue: T): void; 373 374Sets a new value for the property. 375 376**System capability**: SystemCapability.ArkUI.ArkUI.Full 377 378**Parameters** 379 380|Name |Type |Mandatory |Description | 381|---------|-----------|------------|--------------| 382|newValue |T |Yes |New value to set for the property. | 383 384## ISinglePropertyChangeSubscriber\<T\> 385 386Inherits from [IPropertySubscriber](#ipropertysubscriber). Represents a subscriber that subscribes to changes in a property value. 387 388**System capability**: SystemCapability.ArkUI.ArkUI.Full 389 390### hasChanged 391 392hasChanged(newValue: T): void; 393 394Notifies subscribers that the property value has changed. 395 396**System capability**: SystemCapability.ArkUI.ArkUI.Full 397 398**Parameters** 399 400|Name |Type |Mandatory |Description | 401|---------|-----------|------------|--------------| 402|newValue |T |Yes |New value of the property. | 403 404## SubscribaleAbstract 405 406**System capability**: SystemCapability.ArkUI.ArkUI.Full 407 408### owningProperties\_ 409 410private owningProperties_: Set\<number\>; 411 412A set of property IDs that this instance owns. 413 414**System capability**: SystemCapability.ArkUI.ArkUI.Full 415 416**Return value** 417 418|Type |Description | 419|------|------------| 420|Set\<number\> |A set of property IDs. | 421 422### constructor 423 424constructor(); 425 426Constructor. 427 428**System capability**: SystemCapability.ArkUI.ArkUI.Full 429 430### notifyPropertyHasChanged 431 432protected notifyPropertyHasChanged(propName: string, newValue: any): void; 433 434Notify subscribers that a property value has changed. 435 436**System capability**: SystemCapability.ArkUI.ArkUI.Full 437 438**Parameters** 439 440|Name |Type |Mandatory |Description | 441|---------|-----------|------------|--------------| 442|propName |string |Yes |Property name. | 443|newValue |any |No |New value after the change. | 444 445### addOwningProperty 446 447public addOwningProperty(subscriber: IPropertySubscriber): void; 448 449Adds a subscriber to the list of owned properties. 450 451**System capability**: SystemCapability.ArkUI.ArkUI.Full 452 453**Parameters** 454 455|Name |Type |Mandatory |Description | 456|---------|-----------|------------|--------------| 457|subscriber |[IPropertySubscriber](#ipropertysubscriber) |Yes |Subscriber. | 458 459### removeOwningProperty 460 461public removeOwningProperty(property: IPropertySubscriber): void; 462 463Removes a subscriber from the list of owned properties. 464 465**System capability**: SystemCapability.ArkUI.ArkUI.Full 466 467**Parameters** 468 469|Name |Type |Mandatory |Description | 470|---------|-----------|------------|--------------| 471|property |[IPropertySubscriber](#ipropertysubscriber) |Yes |Subscriber to remove. | 472 473### removeOwningPropertyById 474 475public removeOwningPropertyById(subscriberId: number): void; 476 477Removes a subscriber from the list of owned properties by ID. 478 479**System capability**: SystemCapability.ArkUI.ArkUI.Full 480 481**Parameters** 482 483|Name |Type |Mandatory |Description | 484|---------|-----------|------------|--------------| 485|subscriberId |number |Yes |ID of the subscriber to remove. | 486 487## Environment 488 489**System capability**: SystemCapability.ArkUI.ArkUI.Full 490 491### constructor 492 493constructor(); 494 495Constructor. 496 497**System capability**: SystemCapability.ArkUI.ArkUI.Full 498 499## PersistentStorage 500 501**Atomic service API**: This API can be used in atomic services since API version 11. 502 503**System capability**: SystemCapability.ArkUI.ArkUI.Full 504 505### constructor 506 507constructor(appStorage: AppStorage, storage: Storage); 508 509Constructor. 510 511**System capability**: SystemCapability.ArkUI.ArkUI.Full 512 513**Parameters** 514 515|Name |Type |Mandatory |Description | 516|---------|-----------|------------|--------------| 517|appStorage |AppStorage |Yes |Application-level storage. | 518|storage |Storage |Yes |Storage. | 519 520## appStorage 521 522declare const appStorage: AppStorage; 523 524Defines the application-level storage. 525 526**System capability**: SystemCapability.ArkUI.ArkUI.Full 527 528|Type |Description | 529|----------|------------| 530|AppStorage |Application-level storage. | 531