From 6a006577a4d63495cb91d777bf6e42bdfc6fbd81 Mon Sep 17 00:00:00 2001 From: danstarns Date: Sun, 29 Sep 2024 12:36:37 -0700 Subject: [PATCH] docs: add mutable not run api gen --- docs/api/data_source_manager.md | 4 +++- docs/modules/DataSources.md | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/docs/api/data_source_manager.md b/docs/api/data_source_manager.md index 0419f1530..b044ad288 100644 --- a/docs/api/data_source_manager.md +++ b/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 diff --git a/docs/modules/DataSources.md b/docs/modules/DataSources.md index 80ab71700..aaec2243c 100644 --- a/docs/modules/DataSources.md +++ b/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: