mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 10:45:47 +00:00
feature(darwin) DOM.getDataFromStorage -> story
This commit is contained in:
parent
043a2b9613
commit
ffba14d2c1
1 changed files with 69 additions and 46 deletions
|
|
@ -1,6 +1,6 @@
|
|||
var join, ace, load, Util, DOM, io, daffy, restafary;
|
||||
|
||||
(function(global, join, DOM, exec, loadRemote) {
|
||||
(function(global, join, Files, exec, loadRemote) {
|
||||
'use strict';
|
||||
|
||||
if (typeof module !== 'undefined' && module.exports)
|
||||
|
|
@ -21,9 +21,8 @@ var join, ace, load, Util, DOM, io, daffy, restafary;
|
|||
JSHintConfig,
|
||||
|
||||
DIR = '/modules/',
|
||||
Files = DOM.Files,
|
||||
story = new Story(),
|
||||
Emitter = new Events(),
|
||||
Storage = DOM.Storage,
|
||||
MAX_FILE_SIZE = 512000,
|
||||
|
||||
edward = function(el, options, callback) {
|
||||
|
|
@ -322,7 +321,7 @@ var join, ace, load, Util, DOM, io, daffy, restafary;
|
|||
if (error)
|
||||
console.error(error);
|
||||
|
||||
DOM.saveDataToStorage(FileName, Value, hash);
|
||||
story.set(FileName, Value, hash);
|
||||
});
|
||||
|
||||
Emitter._emit('save', Value.length);
|
||||
|
|
@ -333,38 +332,25 @@ var join, ace, load, Util, DOM, io, daffy, restafary;
|
|||
var value = edward.getValue();
|
||||
|
||||
diff(value, function(patch) {
|
||||
var isAllowed = Storage.isAllowed();
|
||||
|
||||
exec.if(!isAllowed, callback, function(func) {
|
||||
DOM.checkStorageHash(path, function(error, equal) {
|
||||
if (!equal)
|
||||
patch = '';
|
||||
|
||||
func(patch);
|
||||
});
|
||||
story.checkHash(path, function(error, equal) {
|
||||
if (!equal)
|
||||
patch = '';
|
||||
|
||||
callback(patch);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function diff(newValue, callback) {
|
||||
loadDiff(function(error) {
|
||||
var patch,
|
||||
isAllowed = Storage.isAllowed();
|
||||
var patch;
|
||||
|
||||
if (error) {
|
||||
alert(error);
|
||||
} else {
|
||||
exec.if(!isAllowed, function() {
|
||||
patch = daffy.createPatch(Value, newValue);
|
||||
exec(callback, patch);
|
||||
}, function(func) {
|
||||
DOM.getDataFromStorage(FileName, function(error, data) {
|
||||
if (data)
|
||||
Value = data;
|
||||
|
||||
func();
|
||||
});
|
||||
});
|
||||
Value = story.get(FileName);
|
||||
patch = daffy.createPatch(Value, newValue);
|
||||
callback(patch);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -478,28 +464,30 @@ var join, ace, load, Util, DOM, io, daffy, restafary;
|
|||
socket.on('patch', function(name, data, hash) {
|
||||
if (name === FileName)
|
||||
loadDiff(function(error) {
|
||||
if (error)
|
||||
var cursor, value, hashLocal;
|
||||
|
||||
if (error) {
|
||||
console.error(error);
|
||||
else
|
||||
DOM.Storage.get(name + '-hash', function(error, hashLocal) {
|
||||
var cursor, value;
|
||||
} else {
|
||||
hashLocal = localStorage.getItem(name + '-hash');
|
||||
|
||||
if (hash === hashLocal) {
|
||||
cursor = edward.getCursor(),
|
||||
value = edward.getValue();
|
||||
value = daffy.applyPatch(value, data);
|
||||
|
||||
if (hash === hashLocal) {
|
||||
cursor = edward.getCursor(),
|
||||
value = edward.getValue();
|
||||
value = daffy.applyPatch(value, data);
|
||||
edward.setValue(value);
|
||||
|
||||
edward.sha(function(error, hash) {
|
||||
story.save(name, value, hash);
|
||||
|
||||
edward.setValue(value);
|
||||
|
||||
edward.sha(function(error, hash) {
|
||||
DOM.saveDataToStorage(name, value, hash);
|
||||
edward
|
||||
.clearSelection()
|
||||
.moveCursorTo(cursor.row, cursor.column)
|
||||
.scrollToLine(cursor.row, true);
|
||||
});
|
||||
}
|
||||
});
|
||||
edward
|
||||
.clearSelection()
|
||||
.moveCursorTo(cursor.row, cursor.column)
|
||||
.scrollToLine(cursor.row, true);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -587,6 +575,41 @@ var join, ace, load, Util, DOM, io, daffy, restafary;
|
|||
document.body.appendChild(element);
|
||||
}
|
||||
|
||||
function Story() {
|
||||
var story = this;
|
||||
|
||||
this.checkHash = function(name, callback) {
|
||||
story.loadHash(name, function(error, loadHash) {
|
||||
var nameHash = name + '-hash',
|
||||
storeHash = localStorage.getItem(nameHash),
|
||||
equal = loadHash === storeHash;
|
||||
|
||||
callback(error, equal);
|
||||
});
|
||||
};
|
||||
|
||||
this.loadHash = function(name, callback) {
|
||||
var query = '?hash';
|
||||
|
||||
restafary.read(name + query, callback);
|
||||
};
|
||||
|
||||
this.set = function(name, data, hash) {
|
||||
var nameHash = name + '-hash',
|
||||
nameData = name + '-data';
|
||||
|
||||
localStorage.setItem(nameHash, hash);
|
||||
localStorage.setItem(nameData, data);
|
||||
};
|
||||
|
||||
this.get = function (name) {
|
||||
var nameData = name + '-data',
|
||||
data = localStorage.getItem(nameData);
|
||||
|
||||
return data;
|
||||
};
|
||||
}
|
||||
|
||||
function Events() {
|
||||
this._all = {};
|
||||
}
|
||||
|
|
@ -616,4 +639,4 @@ var join, ace, load, Util, DOM, io, daffy, restafary;
|
|||
return edward;
|
||||
}
|
||||
|
||||
})(this, join, DOM, Util.exec, DOM.loadRemote);
|
||||
})(this, join, DOM.Files, Util.exec, DOM.loadRemote);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue