Browse Source

Add StorageManager API docs

docs
Artur Arseniev 8 years ago
parent
commit
4ae8a733a2
  1. 1
      docs/.vuepress/config.js
  2. 4
      docs/api.js
  3. 109
      docs/api/storage_manager.md
  4. 31
      src/storage_manager/index.js

1
docs/.vuepress/config.js

@ -60,6 +60,7 @@ module.exports = {
['/api/components', 'DOM Components'],
['/api/panels', 'Panels'],
['/api/style_manager', 'Style Manager'],
['/api/storage_manager', 'Storage Manager'],
],
'/': [
'',

4
docs/api.js

@ -11,9 +11,9 @@ const cmds = [
// ['commands/index.js', 'commands.md'],
// ['dom_components/index.js', 'components.md'],
// ['panels/index.js', 'panels.md'],
['style_manager/index.js', 'style_manager.md'],
// ['style_manager/index.js', 'style_manager.md'],
['storage_manager/index.js', 'storage_manager.md'],
/*
['style_manager/index.js', 'style_manager.md'],
['storage_manager/index.js', 'storage_manager.md'],
['device_manager/index.js', 'device_manager.md'],
['selector_manager/index.js', 'selector_manager.md'],

109
docs/api/storage_manager.md

@ -1,24 +1,49 @@
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
## index
## StorageManager
Before using methods you should get first the module from the editor instance, in this way:
You can customize the initial state of the module from the editor initialization, by passing the following [Configuration Object][1]
```js
var storageManager = editor.StorageManager;
const editor = grapesjs.init({
storageManager: {
// options
}
})
```
Once the editor is instantiated you can use its API. Before using these methods you should get the module from the instance
```js
const storageManager = editor.StorageManager;
```
- [getConfig][2]
- [isAutosave][3]
- [setAutosave][4]
- [getStepsBeforeSave][5]
- [setStepsBeforeSave][6]
- [setStepsBeforeSave][6]
- [getStorages][7]
- [getCurrent][8]
- [getCurrentStorage][9]
- [setCurrent][10]
- [add][11]
- [get][12]
- [store][13]
- [load][14]
## getConfig
Get configuration object
Returns **[Object][1]**
Returns **[Object][15]**
## isAutosave
Checks if autosave is enabled
Returns **[Boolean][2]**
Returns **[Boolean][16]**
## setAutosave
@ -26,7 +51,7 @@ Set autosave value
### Parameters
- `v` **[Boolean][2]**
- `v` **[Boolean][16]**
Returns **this**
@ -34,7 +59,7 @@ Returns **this**
Returns number of steps required before trigger autosave
Returns **[number][3]**
Returns **[number][17]**
## setStepsBeforeSave
@ -42,7 +67,7 @@ Set steps required before trigger autosave
### Parameters
- `v` **[number][3]**
- `v` **[number][17]**
Returns **this**
@ -52,10 +77,10 @@ Add new storage
### Parameters
- `id` **[string][4]** Storage ID
- `storage` **[Object][1]** Storage wrapper
- `storage.load` **[Function][5]** Load method
- `storage.store` **[Function][5]** Store method
- `id` **[string][18]** Storage ID
- `storage` **[Object][15]** Storage wrapper
- `storage.load` **[Function][19]** Load method
- `storage.store` **[Function][19]** Store method
### Examples
@ -87,21 +112,21 @@ Returns storage by id
### Parameters
- `id` **[string][4]** Storage ID
- `id` **[string][18]** Storage ID
Returns **([Object][1] | null)**
Returns **([Object][15] | null)**
## getStorages
Returns all storages
Returns **[Array][6]**
Returns **[Array][20]**
## getCurrent
Returns current storage type
Returns **[string][4]**
Returns **[string][18]**
## setCurrent
@ -109,7 +134,7 @@ Set current storage type
### Parameters
- `id` **[string][4]** Storage ID
- `id` **[string][18]** Storage ID
Returns **this**
@ -119,8 +144,8 @@ Store key-value resources in the current storage
### Parameters
- `data` **[Object][1]** Data in key-value format, eg. {item1: value1, item2: value2}
- `clb` **[Function][5]** Callback function
- `data` **[Object][15]** Data in key-value format, eg. {item1: value1, item2: value2}
- `clb` **[Function][19]** Callback function
### Examples
@ -128,7 +153,7 @@ Store key-value resources in the current storage
storageManager.store({item1: value1, item2: value2});
```
Returns **([Object][1] | null)**
Returns **([Object][15] | null)**
## load
@ -136,8 +161,8 @@ Load resource from the current storage by keys
### Parameters
- `keys` **([string][4] \| [Array][6]&lt;[string][4]>)** Keys to load
- `clb` **[Function][5]** Callback function
- `keys` **([string][18] \| [Array][20]&lt;[string][18]>)** Keys to load
- `clb` **[Function][19]** Callback function
### Examples
@ -156,14 +181,42 @@ Get current storage
Returns **Storage**
[1]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
[1]: https://github.com/artf/grapesjs/blob/master/src/storage_manager/config/config.js
[2]: #getconfig
[3]: #isautosave
[4]: #setautosave
[5]: #getstepsbeforesave
[6]: #setstepsbeforesave
[7]: #getstorages
[8]: #getcurrent
[9]: #getcurrentstorage
[10]: #setcurrent
[11]: #add
[12]: #get
[13]: #store
[14]: #load
[15]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
[2]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
[16]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
[3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
[17]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
[4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
[18]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function
[19]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function
[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
[20]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array

31
src/storage_manager/index.js

@ -1,10 +1,37 @@
/**
* Before using methods you should get first the module from the editor instance, in this way:
* You can customize the initial state of the module from the editor initialization, by passing the following [Configuration Object](https://github.com/artf/grapesjs/blob/master/src/storage_manager/config/config.js)
* ```js
* const editor = grapesjs.init({
* storageManager: {
* // options
* }
* })
* ```
*
* Once the editor is instantiated you can use its API. Before using these methods you should get the module from the instance
*
* ```js
* var storageManager = editor.StorageManager;
* const storageManager = editor.StorageManager;
* ```
*
* * [getConfig](#getconfig)
* * [isAutosave](#isautosave)
* * [setAutosave](#setautosave)
* * [getStepsBeforeSave](#getstepsbeforesave)
* * [setStepsBeforeSave](#setstepsbeforesave)
* * [setStepsBeforeSave](#setstepsbeforesave)
* * [getStorages](#getstorages)
* * [getCurrent](#getcurrent)
* * [getCurrentStorage](#getcurrentstorage)
* * [setCurrent](#setcurrent)
* * [add](#add)
* * [get](#get)
* * [store](#store)
* * [load](#load)
*
* @module StorageManager
*/
module.exports = () => {
var c = {},
defaults = require('./config/config'),

Loading…
Cancel
Save