mirror of
https://github.com/atom/atom.git
synced 2026-02-12 15:45:23 -05:00
43 lines
1.0 KiB
JavaScript
43 lines
1.0 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.deferredCall(this.onUpdate.bind(this));
|
|
|
|
var _self = this;
|
|
sender.on("change", function(e) {
|
|
doc.applyDeltas([e.data]);
|
|
deferredUpdate.schedule(_self.$timeout);
|
|
});
|
|
};
|
|
|
|
(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
|
|
};
|
|
|
|
}).call(Mirror.prototype);
|
|
|
|
}); |