-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
54 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,54 @@ | ||
# flux-eco-ui-tree-state | ||
# FluxUiTreeState | ||
|
||
The FluxUiTreeState API is responsible for creating and managing the state of tree data. | ||
|
||
# Usage | ||
|
||
``` javascript | ||
import { FluxUiTreeStateApi } from "./FluxUiTreeStateApi.js"; | ||
|
||
// Initialize the API | ||
const treeStateApi = await FluxUiTreeStateApi.new({ | ||
publish: (subscriberId, oldState, newState) => { | ||
// Send state change notification | ||
console.log(`State for topic ${topic} changed: ${JSON.stringify(oldState)} -> ${JSON.stringify(newState)}`); | ||
}, | ||
subscribe: (subscriberId, id, callback) => { | ||
// Subscribe to state change notifications | ||
console.log(`Subscribed to state changes for topic ${topic} with ID ${id}`); | ||
}, | ||
unsubscribe: (subscriberId, id) => { | ||
// Unsubscribe from state change notifications | ||
console.log(`Unsubscribed from state changes for topic ${topic} with ID ${id}`); | ||
} | ||
}); | ||
|
||
// Create a tree | ||
const treeId = "my-tree"; | ||
const nodeDataSchema = { | ||
type: "object", | ||
properties: { | ||
label: { type: "string" } | ||
} | ||
}; | ||
await treeStateApi.createTree(treeId, nodeDataSchema); | ||
|
||
// Append a node to the root | ||
const nodeId = "my-first-node"; | ||
const nodeData = { label: "My First Node" }; | ||
await treeStateApi.appendNodeToRoot(treeId, nodeId, nodeData); | ||
|
||
// Append a child node to a parent node | ||
const childNodeId = "a-child-node"; | ||
const childNodeData = { label: "A Child Node" }; | ||
await treeStateApi.appendNodeToParentNode(treeId, "my-first-node", childNodeId, childNodeData); | ||
|
||
// Get the state of the tree | ||
const treeState = await treeStateApi.getState(treeId); | ||
|
||
// Subscribe to state changes | ||
await treeStateApi.subscribeToStateChanged("mySubscriber", treeId, (stateChange) => { | ||
console.log(`State change detected for tree ${treeId}: ${JSON.stringify(stateChange)}`); | ||
}); | ||
|
||
``` |