Skip to content

Allow change handlers for all elements #55

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 26 additions & 19 deletions docs/Elements/ElementsController.md
Original file line number Diff line number Diff line change
Expand Up @@ -357,12 +357,12 @@ still being created by a drawing tool.

### Parameters

| Parameter | Type | Description |
| ----------------- | --------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------- |
| `args` | \{ `options`: \{ `id`: `string`; }; `handler`: (`change`: [`ElementChangeCallbackParams`](ElementChangeCallbackParams.md)) => `void`; } | - |
| `args.options` | \{ `id`: `string`; } | - |
| `args.options.id` | `string` | The id of the element to listen for changes to. |
| `args.handler` | (`change`: [`ElementChangeCallbackParams`](ElementChangeCallbackParams.md)) => `void` | The handler that is called when the element changes. |
| Parameter | Type | Description |
| ------------------ | --------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------- |
| `args` | \{ `options`: \{ `id`: `string`; }; `handler`: (`change`: [`ElementChangeCallbackParams`](ElementChangeCallbackParams.md)) => `void`; } | - |
| `args.options`? | \{ `id`: `string`; } | - |
| `args.options.id`? | `string` | The id of the element to listen for changes to. If not provided, the listener will fire for all elements. |
| `args.handler` | (`change`: [`ElementChangeCallbackParams`](ElementChangeCallbackParams.md)) => `void` | The handler that is called when the element changes. |

### Returns

Expand All @@ -386,18 +386,18 @@ unsubscribe();

## onElementDelete()

> **onElementDelete**(`args`: \{ `options`: \{ `id`: `string`; }; `handler`: () => `void`; }): `VoidFunction`
> **onElementDelete**(`args`: \{ `options`: \{ `id`: `string`; }; `handler`: (`args`: \{ `id`: `string`; }) => `void`; }): `VoidFunction`

Adds a listener for when an element is deleted.

### Parameters

| Parameter | Type | Description |
| ----------------- | -------------------------------------------------------------- | ------------------------------------------------------- |
| `args` | \{ `options`: \{ `id`: `string`; }; `handler`: () => `void`; } | - |
| `args.options` | \{ `id`: `string`; } | - |
| `args.options.id` | `string` | The id of the element to listen for deletions of. |
| `args.handler` | () => `void` | The handler that is called when the element is deleted. |
| Parameter | Type | Description |
| ------------------ | ------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------- |
| `args` | \{ `options`: \{ `id`: `string`; }; `handler`: (`args`: \{ `id`: `string`; }) => `void`; } | - |
| `args.options`? | \{ `id`: `string`; } | - |
| `args.options.id`? | `string` | The id of the element to listen for deletions of. If not provided, the listener will fire for all elements. |
| `args.handler` | (`args`: \{ `id`: `string`; }) => `void` | The handler that is called when the element is deleted. |

### Returns

Expand All @@ -408,13 +408,20 @@ A function to unsubscribe from the listener
### Example

```typescript
// For a specific element
const unsubscribe = felt.onElementDelete({
options: { id: "element-1" },
handler: () => console.log("element-1 deleted"),
});

// For any element
const unsubscribe2 = felt.onElementDelete({
handler: (id) => console.log(id),
});

// later on...
unsubscribe();
unsubscribe2();
```

***
Expand All @@ -427,12 +434,12 @@ Adds a listener for when an element group changes.

### Parameters

| Parameter | Type |
| ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
| `args` | \{ `options`: \{ `id`: `string`; }; `handler`: (`change`: [`ElementGroupChangeCallbackParams`](ElementGroupChangeCallbackParams.md)) => `void`; } |
| `args.options` | \{ `id`: `string`; } |
| `args.options.id` | `string` |
| `args.handler` | (`change`: [`ElementGroupChangeCallbackParams`](ElementGroupChangeCallbackParams.md)) => `void` |
| Parameter | Type | Description |
| ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------- |
| `args` | \{ `options`: \{ `id`: `string`; }; `handler`: (`change`: [`ElementGroupChangeCallbackParams`](ElementGroupChangeCallbackParams.md)) => `void`; } | - |
| `args.options`? | \{ `id`: `string`; } | The options to apply to the listener. If not provided |
| `args.options.id`? | `string` | The id of the element group to listen for changes to. If not provided, the listener will fire for all element groups. |
| `args.handler` | (`change`: [`ElementGroupChangeCallbackParams`](ElementGroupChangeCallbackParams.md)) => `void` | The handler that is called when the element group changes. |

### Returns

Expand Down
45 changes: 26 additions & 19 deletions docs/Main/FeltController.md
Original file line number Diff line number Diff line change
Expand Up @@ -1728,12 +1728,12 @@ still being created by a drawing tool.

### Parameters

| Parameter | Type | Description |
| ----------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------- |
| `args` | \{ `options`: \{ `id`: `string`; }; `handler`: (`change`: [`ElementChangeCallbackParams`](../Elements/ElementChangeCallbackParams.md)) => `void`; } | - |
| `args.options` | \{ `id`: `string`; } | - |
| `args.options.id` | `string` | The id of the element to listen for changes to. |
| `args.handler` | (`change`: [`ElementChangeCallbackParams`](../Elements/ElementChangeCallbackParams.md)) => `void` | The handler that is called when the element changes. |
| Parameter | Type | Description |
| ------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------- |
| `args` | \{ `options`: \{ `id`: `string`; }; `handler`: (`change`: [`ElementChangeCallbackParams`](../Elements/ElementChangeCallbackParams.md)) => `void`; } | - |
| `args.options`? | \{ `id`: `string`; } | - |
| `args.options.id`? | `string` | The id of the element to listen for changes to. If not provided, the listener will fire for all elements. |
| `args.handler` | (`change`: [`ElementChangeCallbackParams`](../Elements/ElementChangeCallbackParams.md)) => `void` | The handler that is called when the element changes. |

### Returns

Expand All @@ -1757,18 +1757,18 @@ unsubscribe();

## onElementDelete()

> **onElementDelete**(`args`: \{ `options`: \{ `id`: `string`; }; `handler`: () => `void`; }): `VoidFunction`
> **onElementDelete**(`args`: \{ `options`: \{ `id`: `string`; }; `handler`: (`args`: \{ `id`: `string`; }) => `void`; }): `VoidFunction`

Adds a listener for when an element is deleted.

### Parameters

| Parameter | Type | Description |
| ----------------- | -------------------------------------------------------------- | ------------------------------------------------------- |
| `args` | \{ `options`: \{ `id`: `string`; }; `handler`: () => `void`; } | - |
| `args.options` | \{ `id`: `string`; } | - |
| `args.options.id` | `string` | The id of the element to listen for deletions of. |
| `args.handler` | () => `void` | The handler that is called when the element is deleted. |
| Parameter | Type | Description |
| ------------------ | ------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------- |
| `args` | \{ `options`: \{ `id`: `string`; }; `handler`: (`args`: \{ `id`: `string`; }) => `void`; } | - |
| `args.options`? | \{ `id`: `string`; } | - |
| `args.options.id`? | `string` | The id of the element to listen for deletions of. If not provided, the listener will fire for all elements. |
| `args.handler` | (`args`: \{ `id`: `string`; }) => `void` | The handler that is called when the element is deleted. |

### Returns

Expand All @@ -1779,13 +1779,20 @@ A function to unsubscribe from the listener
### Example

```typescript
// For a specific element
const unsubscribe = felt.onElementDelete({
options: { id: "element-1" },
handler: () => console.log("element-1 deleted"),
});

// For any element
const unsubscribe2 = felt.onElementDelete({
handler: (id) => console.log(id),
});

// later on...
unsubscribe();
unsubscribe2();
```

***
Expand All @@ -1798,12 +1805,12 @@ Adds a listener for when an element group changes.

### Parameters

| Parameter | Type |
| ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `args` | \{ `options`: \{ `id`: `string`; }; `handler`: (`change`: [`ElementGroupChangeCallbackParams`](../Elements/ElementGroupChangeCallbackParams.md)) => `void`; } |
| `args.options` | \{ `id`: `string`; } |
| `args.options.id` | `string` |
| `args.handler` | (`change`: [`ElementGroupChangeCallbackParams`](../Elements/ElementGroupChangeCallbackParams.md)) => `void` |
| Parameter | Type | Description |
| ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------- |
| `args` | \{ `options`: \{ `id`: `string`; }; `handler`: (`change`: [`ElementGroupChangeCallbackParams`](../Elements/ElementGroupChangeCallbackParams.md)) => `void`; } | - |
| `args.options`? | \{ `id`: `string`; } | The options to apply to the listener. If not provided |
| `args.options.id`? | `string` | The id of the element group to listen for changes to. If not provided, the listener will fire for all element groups. |
| `args.handler` | (`change`: [`ElementGroupChangeCallbackParams`](../Elements/ElementGroupChangeCallbackParams.md)) => `void` | The handler that is called when the element group changes. |

### Returns

Expand Down
16 changes: 9 additions & 7 deletions etc/js-sdk.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ export interface ElementsController {
getElements(
constraint?: GetElementsConstraint): Promise<Array<Element_2 | null>>;
onElementChange(args: {
options: {
id: string;
options?: {
id?: string;
};
handler: (
change: ElementChangeCallbackParams) => void;
Expand All @@ -198,14 +198,16 @@ export interface ElementsController {
}) => void;
}): VoidFunction;
onElementDelete(args: {
options: {
id: string;
options?: {
id?: string;
};
handler: () => void;
handler: (args: {
id: Element_2["id"];
}) => void;
}): VoidFunction;
onElementGroupChange(args: {
options: {
id: string;
options?: {
id?: string;
};
handler: (change: ElementGroupChangeCallbackParams) => void;
}): VoidFunction;
Expand Down
Loading
Loading