Commit c4e4d366 authored by Alex Beregszaszi's avatar Alex Beregszaszi

Add events to files API

parent 9df5608a
'use strict' 'use strict'
var EventManager = require('../lib/eventManager')
function Files (storage) { function Files (storage) {
var event = new EventManager()
this.event = event
var readonly = {} var readonly = {}
this.exists = function (path) { this.exists = function (path) {
...@@ -36,13 +40,20 @@ function Files (storage) { ...@@ -36,13 +40,20 @@ function Files (storage) {
} }
if (!this.isReadOnly(path)) { if (!this.isReadOnly(path)) {
var exists = storage.exists(path)
storage.set(path, content) storage.set(path, content)
if (!exists) {
event.trigger('fileAdded', [path])
} else {
event.trigger('fileChanged', [path])
}
} }
} }
this.addReadOnly = function (path, content) { this.addReadOnly = function (path, content) {
if (!storage.exists(path)) { if (!storage.exists(path)) {
readonly[path] = content readonly[path] = content
event.trigger('fileAdded', [path])
} }
} }
...@@ -60,11 +71,13 @@ function Files (storage) { ...@@ -60,11 +71,13 @@ function Files (storage) {
} else { } else {
storage.remove(path) storage.remove(path)
} }
event.trigger('fileRemoved', [path])
} }
this.rename = function (oldPath, newPath) { this.rename = function (oldPath, newPath) {
if (!this.isReadOnly(oldPath) && storage.exists(oldPath)) { if (!this.isReadOnly(oldPath) && storage.exists(oldPath)) {
storage.rename(oldPath, newPath) storage.rename(oldPath, newPath)
event.trigger('fileRenamed', [oldPath, newPath])
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment