/*! * Copyright (c) Microsoft Corporation and contributors. All rights reserved. * Licensed under the MIT License. */ import { Utils } from "@fluid-experimental/property-changeset"; /** * @fileoverview Defines the base DataBinding that all DataBindings should inherit from. */ import { BaseProperty } from "@fluid-experimental/property-properties"; import { DataBinder, DataBinderHandle, IRegisterOnPathOptions } from "../index.js"; import { PropertyElement } from "../internal/propertyElement.js"; import { IRegisterOnPropertyOptions } from "./IRegisterOnPropertyOptions.js"; import { ModificationContext } from "./modificationContext.js"; import { RemovalContext } from "./removalContext.js"; export interface DataBindingParams { property?: BaseProperty; dataBinder?: DataBinder; bindingType?: string; activationInfo?: any; } export interface DataBindingOptions { simulated?: boolean; calledForReferenceTargetChanged?: boolean; removeRootCallbacks?: boolean; callRootRemovals?: boolean; callRemovals?: boolean; } export interface CallbackOptions { isDeferred?: boolean; } /** * The base class all data bindings should inherit from. using {@link DataBinder.defineDataBinding} and * {@link DataBinder.activateDataBinding}, the class can be instantiated for properties in the workspace * attached to the DataBinder. * * The DataBinding class is told of onPreModify, onModify, onPreRemove, onRemove etc. These can be overloaded * to get the expected behaviors. * In addition, {@link DataBinding.registerOnPath} can be used to register for more granular events regarding * insert, modify and delete for subpaths rooted at the associated property. * @alias DataBinding * @internal */ export declare class DataBinding { static __absolutePathInternalBinding: boolean; _property: BaseProperty | undefined; _referenceCount: number; _activationInfo: any; _referencePropertyTable: {}; _registeredPaths: any; _forEachPrototypeMember: any | undefined; __numDataBinders: number | undefined; _allPathHandles: any | undefined; /** * @constructor * @package * @hideconstructor * @hidden */ constructor(in_params: DataBindingParams); /** * Returns the userData associated with the data binding (if set). This userData value was provided when * the DataBinding was activated using {@link DataBinder.activateDataBinding}. * * @returns The userData, or undefined if it wasn't specified during activation. */ getUserData(): any | undefined; /** * Increment the reference count for this databinding. Databindings can be activated from * multiple paths, however they will only be created once. * * @returns the new reference count * @hidden */ _incReferenceCount(): number; /** * Return the reference count on this databinding. * * @returns the reference count * @hidden */ _getReferenceCount(): number; /** * Decrement the reference count for this databinding. Databindings can be activated from * multiple paths, however they will only be created once. * * @returns the new reference count * @hidden */ _decReferenceCount(): number; /** * Returns the property for which this DataBinding was instantiated. * * @returns The corresponding property. */ getProperty(): BaseProperty | undefined; /** * Returns a string that represents the binding type. This was specified when the DataBinding was * registered with the DataBinder using {@link DataBinder.activateDataBinding}. * * @returns The binding type of this DataBinding. */ getDataBindingType(): string; /** * Returns the DataBinder instance associated with this DataBinding. * * @returns The DataBinder instance. */ getDataBinder(): DataBinder; /** * Returns the Property Element at the tokenized path supplied. The path is assumed to be absolute, or relative * from the Property corresponding to this DataBinding. If the Property is already deleted it returns * undefined. * * @param in_tokenizedPath - the tokenized sub-path / absolute path * @param in_resolveReference - default true; if true, resolve the leaf reference if applicable * @returns the property at the sub-path (or undefined). * @package * @hidden */ getPropertyElementForTokenizedPath(in_tokenizedPath: string[], in_resolveReference?: boolean): PropertyElement; /** * Handler that is called during the initial creation of the DataBinding, once all its children have been * created. Can be overridden by inheriting classes to react to changes to a property that has just been * created. The onPostCreate is called after all children properties have been visited. To react to * a property insertion before the children are visited, add logic to the DataBinding constructor. * * The base class implementation should _not_ be called by inheriting classes. * * @param _in_modificationContext - A context object describing the modification. */ onPostCreate(_in_modificationContext: ModificationContext): void; /** * @param _in_modificationContext - The modifications * @hidden */ _onPostCreate(_in_modificationContext: ModificationContext): void; /** * @param in_modificationContext - The modifications * @hidden * @private */ _invokeInsertCallbacks(in_modificationContext: ModificationContext): void; /** * Handler that is called when this data binding's corresponding property or any of its child properties are modified. * This function will be called before any of the children's onPreModify and onModify handlers. * * The base class implementation should _not_ be called by inheriting classes. * * @param in_modificationContext - A context object describing the modification. */ onPreModify(in_modificationContext: ModificationContext): void; /** * @param in_modificationContext - The modifications * @hidden */ _onPreModify(in_modificationContext: ModificationContext): void; /** * Handler that is called when this data binding's corresponding property or any of its child properties are modified. * This function will be called after all of the children's onPreModify and onModify handlers. * * The base class implementation should _not_ be called by inheriting classes. * * @param n_modificationContext - A context object describing the modification. */ onModify(in_modificationContext: ModificationContext): void; /** * @param in_modificationContext - The modifications * @hidden */ _onModify(in_modificationContext: ModificationContext): void; /** * @param in_modificationContext - The modifications * @hidden */ _invokeModifyCallbacks(in_modificationContext: ModificationContext): void; /** * Handler that is called when the data binding is removed. * This is called before any of the children's onRemove and onPreRemove handlers are called. * * The base class implementation should _not_ be called by inheriting classes. * * @param _in_removalContext - A context object describing the removal event. */ onPreRemove(_in_removalContext: RemovalContext): void; /** * @param _in_removalContext - The removal context * @hidden */ _onPreRemove(_in_removalContext: RemovalContext): void; /** * @param in_tokenizedAbsolutePath - starting absolute path * @param in_simulated - are we pretending something is being removed, or is it for realz? * @hidden * @private */ _invokeRemoveCallbacks(in_tokenizedAbsolutePath: (string | number)[], in_simulated: boolean): void; /** * Handler that is called when the data binding is removed. * This is called after all the children's onRemove and onPreRemove handlers are called. * * The base class implementation should _not_ be called by inheriting classes. * * @param _in_removalContext - A context object describing the removal event. */ onRemove(_in_removalContext: RemovalContext): void; /** * @param in_removalContext - The removal context * @hidden */ _onRemove(in_removalContext: RemovalContext): void; /** * Registers callbacks for all reference properties below the given root property for * which a registered path exists * * @param in_rootProperty - The root property where the registration starts * @param in_registeredSubPaths - The paths for which the user has registered handlers * (this structure has to start at the same root as * in_rootProperty) * @param in_tokenizedFullPath - * The full path from the DataBinding to this reference (including resolved previous references) * @param in_registrySubPath - Path from the root of the reference registry to the * current node * @param in_referencePropertySubTable - * The subtree of the reference property table that starts at the same root as in_registrySubPath * @param in_indirectionsAtRoot - The number of indirections at the root of the * the in_referencePropertySubTable * @param in_previousSourceReferencePropertyInfo - * This contains the reference property table entry for the referencing property. It's used to validate whether * the currently followed reference chain is still valid. * @param in_retroactiveRegister - if false (the default), disable the just-created handler until the end * of processing of the current ChangeSet. When registering retroactively, there is no changeset, and the handler * should be invoked immediately. * @hidden */ _registerCallbacksForReferenceProperties(in_rootProperty: BaseProperty, in_registeredSubPaths: any, in_tokenizedFullPath: (string | number)[], in_registrySubPath: (string | number)[], in_referencePropertySubTable: any, in_indirectionsAtRoot: number, in_previousSourceReferencePropertyInfo: any, in_retroactiveRegister?: boolean): void; /** * helper function to work around a bug in the Property Tree * * @param in_property - the property to dereference * @returns the property at the end of the references, or undefined if there * is none * * @hidden */ _dereferenceProperty(in_property: BaseProperty): BaseProperty | undefined; /** * Registers the callbacks for a specific reference property. If the reference property exists and represents * a valid reference, it will bind against the references in the referenced property for which handlers have * been registered in the _registeredPaths. * * @param in_tokenizedRegistrySubPath - * The path in the handler registry for which the reference callbacks are added * @param in_tokenizedFullPath - * The full path from the data binding to this reference (including resolved previous references) * @param in_registeredSubPaths - * The paths for which the user has registered handlers * @param in_referencePropertySubTable - * The subtree of the reference property table that starts at the same root as in_tokenizedRegistrySubPath * @param in_indirectionsAtRoot - The number of indirections at the root of the * the in_referencePropertySubTable * @param in_referenceProperty - * The property that contains the reference that resulted in this callback. * @param in_previousSourceReferencePropertyInfo - * This contains the reference property table entry for the referencing property. It's used to validate whether * the currently followed reference chain is still valid. * @param in_retroactiveRegister - if false (the default), disable the just-created handler until the end * of processing of the current ChangeSet. When registering retroactively, there is no changeset, and the handler * should be invoked immediately. * @param in_referenceKey - if provided, in_referenceProperty is assumed to be an array/map of references * and this parameter is used as key to identify the exact reference. * @hidden */ private _registerCallbacksForSingleReferenceProperty; /** * Callback that is invoked, if a reference has been changed * * @param in_registeredSubPaths - * The paths for which the user has registered handlers (this structure has to be rooted at the * modified reference) * @param in_referencePropertySubTable - * The subtree of the reference property table that is rooted at the modified reference * @param in_rootPath - The path to which this handler is bound * @param in_rootTypeidHolder - * Object holding the full typeid of the Property at the root of the currently processed ChangeSet * @param in_indirectionsAtRoot - The number of indirections at the root of the * the in_referencePropertySubTable * @param in_previousSourceReferencePropertyInfo - * This contains the reference property table entry for the referencing property. It's used to validate whether * the currently followed reference chain is still valid. * @param in_tokenizedFullPath - * The full path from the data binding to this reference (including resolved previous references) * @param in_tokenizedRegistrySubPath - * @param in_referenceKey - if provided, in_referenceProperty is assumed to be an array/map of references * and this parameter is used as key to identify the exact reference. * @param in_modificationContext - * The modifications / removal information for the reference * @hidden */ private _referenceTargetChanged; /** * This function will handle additional bookkeeping necessary when encountering a reference Property during * handling modifications. * * @param in_indirectionsAtRoot - The number of indirections at the root of in_referencePropertySubTable * @param in_previousSourceReferencePropertyInfo - * This contains the reference property table entry for the referencing property. It's used to validate whether * the currently followed reference chain is still valid. * @param in_context - Traversal context * @param in_nestedRegisteredPath - * The paths for which the user has registered handlers (this structure has to be rooted at the * same property as the modification context) * @param in_tokenizedPath - The (relative) path from the data binding * to the current traversal position (including resolved previous references) * @param in_referencePropertySubTable - * The subtree of the reference property table that is rooted at the same property as the modification context * @param in_calledForReferenceTargetChanged - * This handler was called due to the target of a reference changing * @param in_rootPathOrProperty - * Either the property at which the changeSet processed by this function is rooted, or alternatively * a path to this property. This will be used to resolve other paths. * @param in_tokenizedFullPath - * The full path from the data binding to the current position (including resolved previous references) * @hidden */ _handleReferenceModifications(in_indirectionsAtRoot: number, in_previousSourceReferencePropertyInfo: any, in_context: Utils.TraversalContext, in_nestedRegisteredPath: any, in_tokenizedPath: (string | number)[], in_referencePropertySubTable: any, in_calledForReferenceTargetChanged: boolean, in_rootPathOrProperty: string, in_tokenizedFullPath: Array): void; /** * This function will call the insert, modify and collection* callbacks registered via DataBinding.registerOnPath() * with the appropriate arguments. Additionally, it will take care of binding callbacks to reference properties * to keep track of changes to referenced properties (if a path handler has been registered that traverses the * reference). * * @param in_modificationContext - * The modifications * @param in_registeredSubPaths - * The paths for which the user has registered handlers (this structure has to be rooted at the * same property as the modification context) * @param in_referencePropertySubTable - * The subtree of the reference property table that is rooted at the same property as the modification context * @param in_calledForReferenceTargetChanged - * This handler was called due to the target of a reference changing * @param in_rootPathOrProperty - * Either the property at which the changeSet processed by this function is rooted, or alternatively * a path to this property. This will be used to resolve other paths. * @param in_referencedPropertyTypeidHolder - * Object containing full typeid of the referenced object (including context). * @param in_indirectionsAtRoot - The number of indirections at the root of in_referencePropertySubTable * @param in_previousSourceReferencePropertyInfo - * This contains the reference property table entry for the referencing property. It's used to validate whether * the currently followed reference chain is still valid. * @param in_tokenizedFullPath - * The full path from the Data Binding to the current position (including resolved previous references) * @hidden */ private _handleModifications; /** * This function will call the remove / referenceRemove callbacks registered via DataBinding.registerOnPath() with * the appropriate arguments. Additionally, it will take care of unbinding callbacks to reference properties * to keep track of changes to referenced properties (if a path handler has been registered that traverses the * reference) * * @param in_tokenizedAbsolutePath - the tokenized absolute path for the portion of the * tree we are dealing with. * @param in_registeredSubPaths - * The paths for which the user has registered handlers (this structure has to be rooted at the * same property as the removal context) * @param in_referencePropertySubTable - * The subtree of the reference property table that is rooted at the same property as the removal context * @param in_indirectionsAtRoot - The number of indirections at the root of in_referencePropertySubTable * @param in_options - options for the removal * @param in_options.simulated - removals are simulated * @param in_options.calledForReferenceTargetChanged - * Was this handler indirectly called by a _referenceTargetChanged handler * @param in_options.removeRootCallbacks - * Should any reference target handlers at the root of the tree also be removed? * @param in_options.callRootRemovals - * Should we fire removals for the root of the tree? * @param in_options.callRemovals - fire removal callbacks where appropriate. Otherwise, just tear down * the handles * @private * @hidden */ _handleRemovals(in_tokenizedAbsolutePath: (string | number)[], in_registeredSubPaths: string, in_referencePropertySubTable: any, in_indirectionsAtRoot: number, in_options: DataBindingOptions): void; /** * Implementation of handleRemovals. Wrapper is just to have a default value for in_isRoot and keep * _handleRemovals a wee bit cleaner. * * @inheritdoc _handleRemovals * @hidden */ _handleRemovalsInternal(in_tokenizedAbsolutePath: (string | number)[], in_registeredSubPaths: any, in_referencePropertySubTable: any, in_indirectionsAtRoot: number, in_simulated: boolean | undefined, in_calledForReferenceTargetChanged: boolean, in_removeRootCallbacks: boolean, in_callRootRemovals: boolean, in_callRemovals: boolean, in_isRoot: boolean): void; /** * Invoke the insert callbacks for all the paths in the provided registered paths, perhaps filtered * by in_interestingPaths and in_handle. * * @param in_baseTokenizedPath - where the invocation is relative to, compared to 'this' databinding * @param in_registeredPaths - the registered paths to check * @param in_baseProperty - the property from which the registeredPaths are relative to * @param in_simulated - if true, we are adding in a retroactive case, where the property * already existed and we are simulating * @param in_bindToRef - if true, register callbacks on any reference properties found * @param in_interestingPaths - an optional hierarchy of the paths to examine in * in_registeredPaths. Only paths in this hierarchy and in in_registeredPaths will be considered. By hierarchy, * we mean {a: {b: {}, c: { d:{}}}} will only visit a.b and a.c.d * @param in_handle - restrict the invocation to only registrations relating to in_handle * * @hidden */ _invokeInsertCallbacksForPaths(in_baseTokenizedPath: (string | number)[], in_registeredPaths: any, in_baseProperty: BaseProperty, in_simulated: boolean, in_bindToRef: boolean, in_interestingPaths?: any, in_handle?: DataBinderHandle): void; /** * Augments the prototype of the given data binding class to call the given function for events at the given path(s) * * @param in_dataBindingConstructor - constructor object for the data binding class * @param in_path - the property path(s) for which the function should be called * @param in_operations - * the operations for which the callback function gets called * (one of 'insert', 'modify', 'remove', 'collectionInsert', 'collectionModify', 'collectionRemove', * 'referenceInsert', 'referenceModify', 'referenceRemove') * @param in_function - the function to invoke * @param in_options - Additional user specified options for the callback and its registration * * @returns A handle to unregister this _registerOnPath with * @package * @hidden */ _registerOnPath(in_dataBindingConstructor: typeof DataBinding, in_path: (string | number)[] | string, in_operations: string[], in_function: Function, in_options?: CallbackOptions): DataBinderHandle; /** * Augments the prototype of the given DataBinding class to call the given function for events at the given path. * The callback will get the property at that path as parameter (or undefined if the property no longer exists, e.g. * after a delete or reference change). * * @param in_dataBindingConstructor - constructor object for the data binding class * @param in_path - the property path for which the function should be called on modify() events * @param in_operations - the operations for which the callback function gets called * (one of 'insert', 'modify', 'remove', 'collectionInsert', 'collectionModify', 'collectionRemove') * @param in_function - The function to add * @param in_options - Additional user specified options for the callback and its registration * @param in_options.requireProperty - * If true the callback will only be called if the corresponding Property exists, i.e. it won't be called for * 'remove' events. The default is false. * @package * @hidden */ _registerOnProperty(in_dataBindingConstructor: typeof DataBinding, in_path: string, in_operations: Array, in_function: Function, in_options: IRegisterOnPropertyOptions): void; /** * Helper function to return the runtime object associated to the property this DataBinding is associated with. * By default, it will return the runtime representation for the same binding type of the DataBinding, i.e., * {@link DataBinding.getDataBindingType}. * * Runtime representations are defined with {@link DataBinder.defineRepresentation} * * @param in_bindingType - binding type to fetch; if not specified it will use the same * binding type as the DataBinding. * * @returns The runtime representation associated with the property this binding * is associated with, or undefined if there is no runtime representation registered for this * binding type. If the property associated with this binding is already removed, it throws. * * @throws If the property associated with this DataBinding does not exist anymore (e.g. in onRemove() callbacks) */ getRepresentation(in_bindingType?: string | undefined): T | undefined; /** * Register a callback to a relative property path. It will be triggered on the given events. The callback will * receive the property (at the relative path) as a parameter. * * @example * @snippet javascript 'test/data_binder/data_binding.spec.js' * SnippetStart{DataBinding.registerOnProperty} SnippetEnd{DataBinding.registerOnProperty} * * @param in_path Relative property path. * @param in_events See the `in_events` parameter in {@link DataBinding.registerOnPath} * @param in_callback The function to call, when the property behind the relative path changes. It receives * the property found via path, and a key / index if it gets triggered for one of the collection events. * @param in_options Additional user specified options on how the callback should be * registered. */ static registerOnProperty(in_path: string, in_events: Array, in_callback: Function, in_options?: IRegisterOnPropertyOptions): void; /** * Register a callback to a property path relative to the property associated with the databinding. It will * be triggered on the given events. * If multiple paths are provided for 'in_path', the callback will only be called once per changeset * * See {@link DataBinding.registerOnProperty} for an example; the only difference is the callback will * receive a {@link ModificationContext}. * * @param in_path Path(s) relative to the property to bind on changes. * @param in_events Array of the event names to bind to:
* - modify: Triggered when the property found via the provided path is modified. When the path contains a * ReferenceProperty this event tells us if the referenced property has been modified.
* - insert: Triggered when the property found via the provided path is inserted. when the path contains a * ReferenceProperty this event tells us if the referenced property has been inserted.
* - remove: Triggered when the property found via the provided path is removed. when the path contains a * ReferenceProperty this event tells us if the referenced property has been removed.
* - collectionModify: Triggered when the property found via path is a collection, and an entry is modified. * - collectionInsert: Triggered when the property found via path is a collection, and an entry is inserted. * - collectionRemove: Triggered when the property found via path is a collection, and an entry is removed. * - referenceModify: Triggered when the ReferenceProperty found via path is modified. * - referenceInsert: Triggered when the ReferenceProperty found via path is inserted. * - referenceRemove: Triggered when the ReferenceProperty found via path is removed. * @param in_callback The function to call when the property behind the relative path changes. * @param in_options Additional user specified options on how the callback should be * registered. */ static registerOnPath(in_path: Array | string, in_events: Array, in_callback: Function, in_options?: IRegisterOnPathOptions): void; /** * Same as registerOnProperty, but the callback will get a JSON representation of the value of the property. * * See {@link DataBinding.registerOnProperty} for an example; the only difference is the callback will * receive a JSON representation of the value of the property. * * @param in_path Path relative to the property to bind on value changes. * @param in_events See the `in_events` parameter in {@link DataBinding.registerOnPath} * @param in_callback The function to call, when the property behind the relative path changes. * @param in_options Additional user specified options on how the callback should be * registered. */ static registerOnValues(in_path: string, in_events: Array, in_callback: Function, in_options?: IRegisterOnPathOptions): void; /** * Same as registerOnProperty, but the callback will get a JSON representation of the property. * @param in_path Path relative to the property to bind on value changes. * @param in_events Array of the event names to bind to: modify, insert, remove. * @param in_callback The function to call, when the property behind the relative path changes. * @param in_options Additional user specified options on how the callback should be registered. * * @hidden */ private static _registerOnValues; /** * Same as registerOnProperty, but the callback will get a JSON representation of the property. * @param in_register A function to register relative path callbacks. * @param in_path Path relative to the property to bind on value changes. * @param in_events See {@link DataBinding.registerOnPath [events]} parameter * @param in_callback See {@link DataBinding.registerOnPath [callback]} parameter * @param in_options See {@link DataBinding.registerOnPath [options]} parameter * * @hidden */ private static _handleBinding; } /** * Decorator and decorator factories to register methods of DataBindings as callbacks */ /** * Function to use as a decorator when defining a DataBinding class. When prefixed before a function * on your databinding class, the class will be statically extended to automatically be called back when the * values are changed in the corresponding property. * * @example * @snippet javascript 'test/data_binder/es6_decorator_data_binding.spec.js' * SnippetStart{onValueDecorator} SnippetEnd{onValueDecorator} * * @param in_path Path relative to the property to bind on value changes. * @param in_events See the `in_events` parameter in {@link DataBinding.registerOnPath} * @param in_options Additional user specified options on how the callback should be * registered. * @returns A function that registers the decorated callback using registerOnValues. * @internal */ export declare const onValuesChanged: (_in_path: string, _in_events: Array, _in_options?: IRegisterOnPathOptions) => Function; /** * Function to use as a decorator when defining a DataBinding class. When prefixed before a function * on your databinding class, the class will be statically extended to automatically be called back when the * corresponding property is changed. * * See {@link onValuesChanged} for an example of using decorators. The callback will receive a property * instead of a value. * * @param in_path Path relative to the property to bind on property changes. * @param in_events See the `in_events` parameter in {@link DataBinding.registerOnPath} * @param in_options Additional user specified options on how the callback should be * registered. * @returns function that registers the decorated callback using registerOnProperty. * @internal */ export declare const onPropertyChanged: (_in_path: string, _in_events: Array, _in_options?: IRegisterOnPathOptions) => Function; /** * Function to use as a decorator when defining a DataBinding class. When prefixed before a function * on your databinding class, the class will be statically extended to automatically be called back when the * corresponding property is changed. * * If multiple paths are provided for 'in_path', the callback will only be called once per change set * * See {@link onValuesChanged} for an example of using decorators. The callback will receive a * {@link ModificationContext} instead of a value. * * @param in_path Path(s) relative to the property to bind on changes. * @param in_events See the `in_events` parameter in {@link DataBinding.registerOnPath} * @param in_options Additional user specified options on how the callback should be * registered. * @returns A function that registers the decorated callback using registerOnPath. * @internal */ export declare const onPathChanged: (_in_path: Array | string, _in_events: Array, _in_options?: IRegisterOnPathOptions) => Function; //# sourceMappingURL=dataBinding.d.ts.map