Browse Source

docs: add mutable not run api gen

pull/6176/head
danstarns 1 year ago
parent
commit
6a006577a4
  1. 4
      docs/api/data_source_manager.md
  2. 24
      docs/modules/DataSources.md

4
docs/api/data_source_manager.md

@ -130,7 +130,7 @@ data record, and optional property path.
Store data sources to a JSON object.
Returns **[Object][6]** Stored data sources.
Returns **[Array][8]** Stored data sources.
## load
@ -155,3 +155,5 @@ Returns **[Object][6]** Loaded data sources.
[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
[8]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array

24
docs/modules/DataSources.md

@ -211,6 +211,30 @@ console.log(loadedDataSource.getRecord('id1').get('content')); // Outputs: "This
Remember that DataSources with `skipFromStorage: true` will not be available after a project is loaded unless you add them programmatically.
## Record Mutability
DataSource records are mutable by default, but can be set as immutable to prevent modifications. Use the mutable flag when creating records to control this behavior.
```ts
const dataSource = {
id: 'my-datasource',
records: [
{ id: 'id1', content: 'Mutable content' },
{ id: 'id2', content: 'Immutable content', mutable: false },
],
};
editor.DataSources.add(dataSource);
const ds = editor.DataSources.get('my-datasource');
ds.getRecord('id1').set('content', 'Updated content'); // Succeeds
ds.getRecord('id2').set('content', 'New content'); // Throws error
```
Immutable records cannot be modified or removed, ensuring data integrity for critical information.
## Benefits of Using DataSources
DataSources are integrated with GrapesJS's runtime and BackboneJS models, enabling dynamic updates and synchronization between your data and UI components. This allows you to:

Loading…
Cancel
Save