mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-04 20:33:12 -05:00
50 lines
1.1 KiB
JavaScript
50 lines
1.1 KiB
JavaScript
|
define(function(require, exports, module) {
|
||
|
"use strict";
|
||
|
|
||
|
var Document = require("../document").Document;
|
||
|
var lang = require("../lib/lang");
|
||
|
|
||
|
var Mirror = exports.Mirror = function(sender) {
|
||
|
this.sender = sender;
|
||
|
var doc = this.doc = new Document("");
|
||
|
|
||
|
var deferredUpdate = this.deferredUpdate = lang.delayedCall(this.onUpdate.bind(this));
|
||
|
|
||
|
var _self = this;
|
||
|
sender.on("change", function(e) {
|
||
|
doc.applyDeltas(e.data);
|
||
|
if (_self.$timeout)
|
||
|
return deferredUpdate.schedule(_self.$timeout);
|
||
|
_self.onUpdate();
|
||
|
});
|
||
|
};
|
||
|
|
||
|
(function() {
|
||
|
|
||
|
this.$timeout = 500;
|
||
|
|
||
|
this.setTimeout = function(timeout) {
|
||
|
this.$timeout = timeout;
|
||
|
};
|
||
|
|
||
|
this.setValue = function(value) {
|
||
|
this.doc.setValue(value);
|
||
|
this.deferredUpdate.schedule(this.$timeout);
|
||
|
};
|
||
|
|
||
|
this.getValue = function(callbackId) {
|
||
|
this.sender.callback(this.doc.getValue(), callbackId);
|
||
|
};
|
||
|
|
||
|
this.onUpdate = function() {
|
||
|
// abstract method
|
||
|
};
|
||
|
|
||
|
this.isPending = function() {
|
||
|
return this.deferredUpdate.isPending();
|
||
|
};
|
||
|
|
||
|
}).call(Mirror.prototype);
|
||
|
|
||
|
});
|