electron-localdata
v1.0.0
Published
An Electron data store that supports listening events
Downloads
1
Readme
electron-localdata
An Electron data store that supports listening events
Features
- Support the "main process" and "renderer process" sync read & write
- Supports event monitoring for "main process" and "renderer process"
- You can set the data key name as a localData instance of property name, easy to read and write
- No dependence
Installation
npm install --save electron-localdata
API
LocalData(filepath, sync_write=true, keys)
- filepath: The data store the file path, relative to the "userData"
- sync_write: The default is true, when the data changes after synchronization storage, if set to false, need to manually call the save method
- keys: Set the key name of the data as the attribute name of the LocalData instance
const LocalData = require('electron-localdata') let localdata = new LocalData('test.json', true, ['abc'])
LocalData.create(filepath, sync_write=true, keys)
This method is equivalent to new LocalData (), but if the data instance exists, it will return to the instance
LocalData.prototype.on(event_name, callback)
localdata.on('changed', (event)=>{}) // event = {type, key, newValue, oldValue} localdata.on('deleted', (event)=>{}) localdata.on('saved', (event)=>{}) localdata.on('close', (event)=>{})
LocalData.prototype.get(key)
LocalData.prototype.set(key, value)
LocalData.prototype.keys()
LocalData.prototype.delete(key)
LocalData.prototype.save()
LocalData.prototype.close()
LocalData.prototype.property(keys)
localdata.property(['abc', 'efg']) localdata.abc = 123 console.log(localdata.abc)
支持监听事件的 Electron 数据存储库
特点
- 支持 “主程序“ 端 与 “渲染端“ 同时读写一份数据
- 支持 “主程序“ 端 与 “渲染端“ 的事件监听,任意一端发声改变,会同时接收到消息
- 可设置数据的键名作为 LocalData 实例的属性名,方便的读写数据的
- 无依赖
API
LocalData(filepath, sync_write=true, keys)
- filepath: 数据存储的文件路径,相对于 userData 目录
- sync_write: 默认为 true,当数据改变后同步存储,如果设置为 false,需手动调用 save 方法
- keys: 设置数据的键名用作 LocalData 实例的属性名
const LocalData = require('electron-localdata') let localdata = new LocalData('test.json', true, ['abc'])
LocalData.create(filepath, sync_write=true, keys)
此方法等同 new LocalData(),但如果数据实例以存在的话,会返回以存在实例