FormKit Observer is a utility to wrap a FormKitNode in a dependency tracking observer proxy.
Creates the observer.
createObserver(node: FormKitNode, dependencies?: FormKitDependencies): FormKitObservedNode;
node
— The FormKitNode to observe.dependencies
optional — The dependent nodes and the events that are required to watch for changes.Returns a FormKitObservedNode.
Determines which nodes should be added as dependencies and which should be removed.
diffDeps(previous: FormKitDependencies, current: FormKitDependencies): [FormKitDependencies, FormKitDependencies];
previous
— The previous watcher dependencies.current
— The new/current watcher dependencies.A tuple of maps: toAdd
and toRemove
.
Checks if the given node is revoked.
isKilled(node: FormKitObservedNode): boolean;
node
— Any observed node to check.A boolean
indicating if the node is revoked.
Remove all the receipts from the observed node and subtree.
removeListeners(receipts: FormKitObserverReceipts): void;
receipts
— The FormKit observer receipts to remove.An API-compatible FormKitNode that is able to determine the full dependency tree of nodes and their values.
interface FormKitObservedNode extends FormKitNode {
_node: FormKitNode;
deps: FormKitDependencies;
kill: () => undefined;
observe: () => void;
receipts: FormKitObserverReceipts;
stopObserve: () => FormKitDependencies;
watch:<TextendsFormKitWatchable>(block: T, after?: (value: ReturnType<T>) => void) => void;
}
A callback to watch for nodes.
interface FormKitWatchable<T = unknown> {
(node: FormKitObservedNode): T;
}
The dependent nodes and the events that are required to watch for changes.
export type FormKitDependencies = Map<FormKitNode, Set<string>> & {
active?: boolean;
};
A Map of nodes with the values being Maps of eventsName: receipt
export type FormKitObserverReceipts = Map<FormKitNode, {
[index: string]: string;
}>;