Skip to content

Commit 873989f

Browse files
committed
Make element change/delete handlers have optional IDs
1 parent 1c66fc8 commit 873989f

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
@@ -342,12 +342,12 @@ still being created by a drawing tool.
342342

343343
### Parameters
344344

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

352352
### Returns
353353

@@ -371,18 +371,18 @@ unsubscribe();
371371

372372
## onElementDelete()
373373

374-
> **onElementDelete**(`args`: \{ `options`: \{ `id`: `string`; }; `handler`: () => `void`; }): `VoidFunction`
374+
> **onElementDelete**(`args`: \{ `options`: \{ `id`: `string`; }; `handler`: (`args`: \{ `id`: `string`; }) => `void`; }): `VoidFunction`
375375
376376
Adds a listener for when an element is deleted.
377377

378378
### Parameters
379379

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

387387
### Returns
388388

@@ -393,13 +393,20 @@ A function to unsubscribe from the listener
393393
### Example
394394

395395
```typescript
396+
// For a specific element
396397
const unsubscribe = felt.onElementDelete({
397398
options: { id: "element-1" },
398399
handler: () => console.log("element-1 deleted"),
399400
});
400401

402+
// For any element
403+
const unsubscribe2 = felt.onElementDelete({
404+
handler: (id) => console.log(id),
405+
});
406+
401407
// later on...
402408
unsubscribe();
409+
unsubscribe2();
403410
```
404411

405412
***
@@ -412,12 +419,12 @@ Adds a listener for when an element group changes.
412419

413420
### Parameters
414421

415-
| Parameter | Type |
416-
| ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
417-
| `args` | \{ `options`: \{ `id`: `string`; }; `handler`: (`change`: [`ElementGroupChangeCallbackParams`](ElementGroupChangeCallbackParams.md)) => `void`; } |
418-
| `args.options` | \{ `id`: `string`; } |
419-
| `args.options.id` | `string` |
420-
| `args.handler` | (`change`: [`ElementGroupChangeCallbackParams`](ElementGroupChangeCallbackParams.md)) => `void` |
422+
| Parameter | Type | Description |
423+
| ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------- |
424+
| `args` | \{ `options`: \{ `id`: `string`; }; `handler`: (`change`: [`ElementGroupChangeCallbackParams`](ElementGroupChangeCallbackParams.md)) => `void`; } | - |
425+
| `args.options`? | \{ `id`: `string`; } | The options to apply to the listener. If not provided |
426+
| `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. |
427+
| `args.handler` | (`change`: [`ElementGroupChangeCallbackParams`](ElementGroupChangeCallbackParams.md)) => `void` | The handler that is called when the element group changes. |
421428

422429
### Returns
423430

docs/Main/FeltController.md

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

17161716
### Parameters
17171717

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

17251725
### Returns
17261726

@@ -1744,18 +1744,18 @@ unsubscribe();
17441744

17451745
## onElementDelete()
17461746

1747-
> **onElementDelete**(`args`: \{ `options`: \{ `id`: `string`; }; `handler`: () => `void`; }): `VoidFunction`
1747+
> **onElementDelete**(`args`: \{ `options`: \{ `id`: `string`; }; `handler`: (`args`: \{ `id`: `string`; }) => `void`; }): `VoidFunction`
17481748
17491749
Adds a listener for when an element is deleted.
17501750

17511751
### Parameters
17521752

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

17601760
### Returns
17611761

@@ -1766,13 +1766,20 @@ A function to unsubscribe from the listener
17661766
### Example
17671767

17681768
```typescript
1769+
// For a specific element
17691770
const unsubscribe = felt.onElementDelete({
17701771
options: { id: "element-1" },
17711772
handler: () => console.log("element-1 deleted"),
17721773
});
17731774

1775+
// For any element
1776+
const unsubscribe2 = felt.onElementDelete({
1777+
handler: (id) => console.log(id),
1778+
});
1779+
17741780
// later on...
17751781
unsubscribe();
1782+
unsubscribe2();
17761783
```
17771784

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

17861793
### Parameters
17871794

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

17951802
### Returns
17961803

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)