我有兴趣修改这个项目: Bookmarking App with Electron
这是我与Electron的第一次互动,这个项目使用Firebase,但我不熟悉它,如果我可以使用本地.json
文件存储,那将是非常好的。处理数据库的代码是:
import { EventEmitter } from 'events'
import Firebase from 'firebase'
// ENTER YOUR FIREBASE URL BELOW
const db = Firebase.initializeApp({
apiKey: 'YOUR_FIREBASE_APP_SECRET',
databaseURL: 'https://YOUR_FIREBASE_APP.firebaseio.com/',
});
const categoriesRef = db.database().ref().child('categories')
const bookmarksRef = db.database().ref().child('bookmarks')
const store = new EventEmitter()
let categories = {}
let bookmarks = {}
db.database().ref().on('value', (snapshot) => {
var bookmarkData = snapshot.val()
if (bookmarkData) {
categories = bookmarkData.categories
bookmarks = bookmarkData.bookmarks
store.emit('data-updated', categories, bookmarks)
}
})
store.addCategory = (category) => {
categoriesRef.update(category)
}
store.deleteCategory = (catName) => {
// first check if an 'Uncategorized' category exists, if not, create it
if (!('Uncategorized' in categories)) {
categoriesRef.update({ 'Uncategorized': 'white' })
}
for (var key in bookmarks) {
if (bookmarks[key].category === catName) {
bookmarksRef.child(key).update({ category: 'Uncategorized' })
}
}
categoriesRef.child(catName).remove()
}
store.addBookmark = (bookmark) => {
bookmarksRef.push(bookmark)
}
store.deleteBookmark = (bookmarkId) => {
bookmarksRef.child(bookmarkId).remove()
}
export default store
我的目标是使用本地.json
文件进行存储,但我对系统编程的JavaScript并不熟悉,所以这可能很简单。