Skip to content

Commit dcfb69b

Browse files
committed
Make element change/delete handlers have optional IDs
1 parent a4ff116 commit dcfb69b

File tree

6 files changed

+107
-67
lines changed

6 files changed

+107
-67
lines changed

docs/Elements/ElementsController.md

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -357,12 +357,12 @@ still being created by a drawing tool.
357357

358358
### Parameters
359359

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

367367
### Returns
368368

@@ -386,18 +386,18 @@ unsubscribe();
386386

387387
## onElementDelete()
388388

389-
> **onElementDelete**(`args`: \{ `options`: \{ `id`: `string`; }; `handler`: () => `void`; }): `VoidFunction`
389+
> **onElementDelete**(`args`: \{ `options`: \{ `id`: `string`; }; `handler`: (`args`: \{ `id`: `string`; }) => `void`; }): `VoidFunction`
390390
391391
Adds a listener for when an element is deleted.
392392

393393
### Parameters
394394

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

402402
### Returns
403403

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

410410
```typescript
411+
// For a specific element
411412
const unsubscribe = felt.onElementDelete({
412413
options: { id: "element-1" },
413414
handler: () => console.log("element-1 deleted"),
414415
});
415416

417+
// For any element
418+
const unsubscribe2 = felt.onElementDelete({
419+
handler: (id) => console.log(id),
420+
});
421+
416422
// later on...
417423
unsubscribe();
424+
unsubscribe2();
418425
```
419426

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

428435
### Parameters
429436

430-
| Parameter | Type |
431-
| ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
432-
| `args` | \{ `options`: \{ `id`: `string`; }; `handler`: (`change`: [`ElementGroupChangeCallbackParams`](ElementGroupChangeCallbackParams.md)) => `void`; } |
433-
| `args.options` | \{ `id`: `string`; } |
434-
| `args.options.id` | `string` |
435-
| `args.handler` | (`change`: [`ElementGroupChangeCallbackParams`](ElementGroupChangeCallbackParams.md)) => `void` |
437+
| Parameter | Type | Description |
438+
| ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------- |
439+
| `args` | \{ `options`: \{ `id`: `string`; }; `handler`: (`change`: [`ElementGroupChangeCallbackParams`](ElementGroupChangeCallbackParams.md)) => `void`; } | - |
440+
| `args.options`? | \{ `id`: `string`; } | The options to apply to the listener. If not provided |
441+
| `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. |
442+
| `args.handler` | (`change`: [`ElementGroupChangeCallbackParams`](ElementGroupChangeCallbackParams.md)) => `void` | The handler that is called when the element group changes. |
436443

437444
### Returns
438445

docs/Main/FeltController.md

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1722,12 +1722,12 @@ still being created by a drawing tool.
17221722

17231723
### Parameters
17241724

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

17321732
### Returns
17331733

@@ -1751,18 +1751,18 @@ unsubscribe();
17511751

17521752
## onElementDelete()
17531753

1754-
> **onElementDelete**(`args`: \{ `options`: \{ `id`: `string`; }; `handler`: () => `void`; }): `VoidFunction`
1754+
> **onElementDelete**(`args`: \{ `options`: \{ `id`: `string`; }; `handler`: (`args`: \{ `id`: `string`; }) => `void`; }): `VoidFunction`
17551755
17561756
Adds a listener for when an element is deleted.
17571757

17581758
### Parameters
17591759

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

17671767
### Returns
17681768

@@ -1773,13 +1773,20 @@ A function to unsubscribe from the listener
17731773
### Example
17741774

17751775
```typescript
1776+
// For a specific element
17761777
const unsubscribe = felt.onElementDelete({
17771778
options: { id: "element-1" },
17781779
handler: () => console.log("element-1 deleted"),
17791780
});
17801781

1782+
// For any element
1783+
const unsubscribe2 = felt.onElementDelete({
1784+
handler: (id) => console.log(id),
1785+
});
1786+
17811787
// later on...
17821788
unsubscribe();
1789+
unsubscribe2();
17831790
```
17841791

17851792
***
@@ -1792,12 +1799,12 @@ Adds a listener for when an element group changes.
17921799

17931800
### Parameters
17941801

1795-
| Parameter | Type |
1796-
| ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
1797-
| `args` | \{ `options`: \{ `id`: `string`; }; `handler`: (`change`: [`ElementGroupChangeCallbackParams`](../Elements/ElementGroupChangeCallbackParams.md)) => `void`; } |
1798-
| `args.options` | \{ `id`: `string`; } |
1799-
| `args.options.id` | `string` |
1800-
| `args.handler` | (`change`: [`ElementGroupChangeCallbackParams`](../Elements/ElementGroupChangeCallbackParams.md)) => `void` |
1802+
| Parameter | Type | Description |
1803+
| ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------- |
1804+
| `args` | \{ `options`: \{ `id`: `string`; }; `handler`: (`change`: [`ElementGroupChangeCallbackParams`](../Elements/ElementGroupChangeCallbackParams.md)) => `void`; } | - |
1805+
| `args.options`? | \{ `id`: `string`; } | The options to apply to the listener. If not provided |
1806+
| `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. |
1807+
| `args.handler` | (`change`: [`ElementGroupChangeCallbackParams`](../Elements/ElementGroupChangeCallbackParams.md)) => `void` | The handler that is called when the element group changes. |
18011808

18021809
### Returns
18031810

etc/js-sdk.api.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@ export interface ElementsController {
171171
getElements(
172172
constraint?: GetElementsConstraint): Promise<Array<Element_2 | null>>;
173173
onElementChange(args: {
174-
options: {
175-
id: string;
174+
options?: {
175+
id?: string;
176176
};
177177
handler: (
178178
change: ElementChangeCallbackParams) => void;
@@ -186,14 +186,16 @@ export interface ElementsController {
186186
}) => void;
187187
}): VoidFunction;
188188
onElementDelete(args: {
189-
options: {
190-
id: string;
189+
options?: {
190+
id?: string;
191191
};
192-
handler: () => void;
192+
handler: (args: {
193+
id: Element_2["id"];
194+
}) => void;
193195
}): VoidFunction;
194196
onElementGroupChange(args: {
195-
options: {
196-
id: string;
197+
options?: {
198+
id?: string;
197199
};
198200
handler: (change: ElementGroupChangeCallbackParams) => void;
199201
}): VoidFunction;

0 commit comments

Comments
 (0)