FIX: Update non-Ember CLI ember-buffered-proxy (#13227)

This version matches the one we have in discourse/package.json.

Fixes an issue with saving topic name form w/o any changes.
This commit is contained in:
Jarek Radosz 2021-06-01 16:49:03 +02:00 committed by GitHub
parent 8a99ee88bd
commit eb6a6446ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 120 additions and 44 deletions

View File

@ -26,10 +26,6 @@ define("ember-buffered-proxy/proxy", ["exports"], function (__exports__) {
__exports__.default = window.BufferedProxy; __exports__.default = window.BufferedProxy;
}); });
define("ember-buffered-proxy/mixin", ["exports"], function (__exports__) {
__exports__.default = null;
});
define("bootbox", ["exports"], function (__exports__) { define("bootbox", ["exports"], function (__exports__) {
__exports__.default = window.bootbox; __exports__.default = window.bootbox;
}); });

View File

@ -1,8 +1,6 @@
import discourseComputed, { on } from "discourse-common/utils/decorators"; import discourseComputed, { on } from "discourse-common/utils/decorators";
import BufferedMixin from "ember-buffered-proxy/mixin";
import BufferedProxy from "ember-buffered-proxy/proxy"; import BufferedProxy from "ember-buffered-proxy/proxy";
import Controller from "@ember/controller"; import Controller from "@ember/controller";
import EmberObjectProxy from "@ember/object/proxy";
import Evented from "@ember/object/evented"; import Evented from "@ember/object/evented";
import ModalFunctionality from "discourse/mixins/modal-functionality"; import ModalFunctionality from "discourse/mixins/modal-functionality";
import { ajax } from "discourse/lib/ajax"; import { ajax } from "discourse/lib/ajax";
@ -17,8 +15,7 @@ export default Controller.extend(ModalFunctionality, Evented, {
@discourseComputed("site.categories.[]") @discourseComputed("site.categories.[]")
categoriesBuffered(categories) { categoriesBuffered(categories) {
const bufProxy = EmberObjectProxy.extend(BufferedMixin || BufferedProxy); return (categories || []).map((c) => BufferedProxy.create({ content: c }));
return (categories || []).map((c) => bufProxy.create({ content: c }));
}, },
categoriesOrdered: sort("categoriesBuffered", "categoriesSorting"), categoriesOrdered: sort("categoriesBuffered", "categoriesSorting"),

View File

@ -1,13 +1,11 @@
import BufferedMixin from "ember-buffered-proxy/mixin";
import BufferedProxy from "ember-buffered-proxy/proxy"; import BufferedProxy from "ember-buffered-proxy/proxy";
import EmberObjectProxy from "@ember/object/proxy";
import Mixin from "@ember/object/mixin"; import Mixin from "@ember/object/mixin";
import { computed } from "@ember/object"; import { computed } from "@ember/object";
export function bufferedProperty(property) { export function bufferedProperty(property) {
const mixin = { const mixin = {
buffered: computed(property, function () { buffered: computed(property, function () {
return EmberObjectProxy.extend(BufferedMixin || BufferedProxy).create({ return BufferedProxy.create({
content: this.get(property), content: this.get(property),
}); });
}), }),

View File

@ -1,6 +1,12 @@
(function (global) { (function (global) {
"use strict"; "use strict";
function aliasMethod(methodName) {
return function() {
return this[methodName].apply(this, arguments);
};
}
function empty(obj) { function empty(obj) {
var key; var key;
for (key in obj) if (obj.hasOwnProperty(key)) return false; for (key in obj) if (obj.hasOwnProperty(key)) return false;
@ -8,77 +14,156 @@
} }
var Ember = global.Ember, var Ember = global.Ember,
get = Ember.get, set = Ember.set; get = Ember.get, set = Ember.set,
isArray = Ember.isArray, getProperties = Ember.getProperties,
notifyPropertyChange = Ember.notifyPropertyChange,
meta = Ember.meta, defineProperty = Ember.defineProperty;
var BufferedProxy = Ember.Mixin.create({ var hasOwnProp = Object.prototype.hasOwnProperty;
var BufferedProxyMixin = Ember.Mixin.create({
buffer: null, buffer: null,
hasBufferedChanges: false, hasBufferedChanges: false,
unknownProperty: function (key) { hasChanges: Ember.computed.readOnly('hasBufferedChanges'),
var buffer = this.buffer;
return buffer && buffer.hasOwnProperty(key) ? buffer[key] : this._super(key); applyChanges: function() {
return this.applyBufferedChanges(...arguments);
}, },
setUnknownProperty: function (key, value) { discardChanges: function() {
if (!this.buffer) this.buffer = {}; return this.discardBufferedChanges(...arguments);
},
var buffer = this.buffer, init: function() {
content = this.get('content'), this.initializeBuffer();
current = content && get(content, key), set(this, 'hasBufferedChanges', false);
previous = buffer.hasOwnProperty(key) ? buffer[key] : current; this._super(...arguments);
},
if (previous === value) return; initializeBuffer: function(onlyTheseKeys) {
if(isArray(onlyTheseKeys) && !empty(onlyTheseKeys)) {
onlyTheseKeys.forEach((key) => delete this.buffer[key]);
}
else {
set(this, 'buffer', Object.create(null));
}
},
unknownProperty: function(key) {
var buffer = get(this, 'buffer');
return (hasOwnProp.call(buffer, key)) ? buffer[key] : this._super(key);
},
setUnknownProperty: function(key, value) {
var m = meta(this);
if (m.proto === this || (m.isInitializing && m.isInitializing())) {
defineProperty(this, key, null, value);
return value;
}
var props = getProperties(this, ['buffer', 'content']),
buffer = props.buffer,
content = props.content,
current,
previous;
if (content != null) {
current = get(content, key);
}
previous = hasOwnProp.call(buffer, key) ? buffer[key] : current;
if (previous === value) {
return;
}
if (current === value) { if (current === value) {
delete buffer[key]; delete buffer[key];
if (empty(buffer)) { if (empty(buffer)) {
this.set('hasBufferedChanges', false); set(this, 'hasBufferedChanges', false);
} }
} else { } else {
buffer[key] = value; buffer[key] = value;
this.set('hasBufferedChanges', true); set(this, 'hasBufferedChanges', true);
} }
this.notifyPropertyChange(key); notifyPropertyChange(content, key);
return value; return value;
}, },
applyBufferedChanges: function() { applyBufferedChanges: function(onlyTheseKeys) {
var buffer = this.buffer, var props = getProperties(this, ['buffer', 'content']),
content = this.get('content'), buffer = props.buffer,
content = props.content,
key; key;
for (key in buffer) {
if (!buffer.hasOwnProperty(key)) continue; Object.keys(buffer).forEach((key) => {
if (isArray(onlyTheseKeys) && onlyTheseKeys.indexOf(key) === -1) {
return;
}
set(content, key, buffer[key]); set(content, key, buffer[key]);
});
this.initializeBuffer(onlyTheseKeys);
if (empty(get(this, 'buffer'))) {
set(this, 'hasBufferedChanges', false);
} }
this.buffer = {};
this.set('hasBufferedChanges', false);
}, },
discardBufferedChanges: function() { discardBufferedChanges: function(onlyTheseKeys) {
var buffer = this.buffer, var props = getProperties(this, ['buffer', 'content']),
content = this.get('content'), buffer = props.buffer,
content = props.content,
key; key;
for (key in buffer) {
if (!buffer.hasOwnProperty(key)) continue;
delete buffer[key]; this.initializeBuffer(onlyTheseKeys);
this.notifyPropertyChange(key);
Object.keys(buffer).forEach((key) => {
if (isArray(onlyTheseKeys) && onlyTheseKeys.indexOf(key) === -1) {
return;
}
notifyPropertyChange(content, key);
});
if (empty(get(this, 'buffer'))) {
set(this, 'hasBufferedChanges', false);
} }
this.set('hasBufferedChanges', false); },
hasChanged: function(key) {
var props = getProperties(this, ['buffer', 'content']),
buffer = props.buffer,
content = props.content,
key;
if (typeof key !== 'string' || typeof get(buffer, key) === 'undefined') {
return false;
}
if (get(buffer, key) !== get(content, key)) {
return true;
}
return false;
} }
}); });
var BufferedProxy = Ember.ObjectProxy.extend(BufferedProxyMixin);
// CommonJS module // CommonJS module
if (typeof module !== 'undefined' && module.exports) { if (typeof module !== 'undefined' && module.exports) {
module.exports = BufferedProxy; module.exports = BufferedProxy;
} else if (typeof define === "function" && define.amd) { } else if (typeof define === "function" && define.amd) {
define("buffered-proxy", function (require, exports, module) { define("ember-buffered-proxy/proxy", function (require, exports, module) {
return BufferedProxy; return BufferedProxy;
}); });
} else { } else {
global.BufferedProxy = BufferedProxy; global.BufferedProxy = BufferedProxy;
} }
}(this)); }(this));