| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- var EventInstanceDataSource = Class.extend(EmitterMixin, {
- instanceRepo: null,
- freezeDepth: 0,
- outboundChangeset: null,
- isPopulated: false,
- constructor: function() {
- this.instanceRepo = new EventInstanceRepo();
- },
- tryReset: function() {
- if (this.isPopulated && this.canTrigger()) {
- this.triggerChangeset(new EventInstanceChangeset(
- true, // isClear
- null, // removals
- this.instanceRepo // additions
- ));
- }
- },
- // Reporting and Triggering
- // -----------------------------------------------------------------------------------------------------------------
- addChangeset: function(changeset) {
- if (!this.outboundChangeset) {
- this.outboundChangeset = new EventInstanceChangeset();
- }
- changeset.applyToChangeset(this.outboundChangeset);
- this.trySendOutbound();
- },
- freeze: function() {
- this.freezeDepth++;
- },
- thaw: function() {
- this.freezeDepth--;
- this.trySendOutbound();
- },
- trySendOutbound: function() { // also might apply outbound changes to INTERNAL data
- var outboundChangeset = this.outboundChangeset;
- if (this.canTrigger()) {
- this.isPopulated = true; // event if empty result, consider populated
- if (outboundChangeset) {
- outboundChangeset.applyToRepo(this.instanceRepo); // finally internally record
- this.outboundChangeset = null;
- this.triggerChangeset(outboundChangeset);
- }
- else {
- // hack for eventAfterAllRender
- // also for DateComponents to know an empy, but populated, state
- this.triggerChangeset(new EventInstanceChangeset());
- }
- }
- },
- canTrigger: function() {
- return !this.freezeDepth;
- },
- triggerChangeset: function(changeset) {
- this.trigger('before:receive');
- this.trigger('receive', changeset);
- this.trigger('after:receive');
- }
- });
|