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;
});
define("ember-buffered-proxy/mixin", ["exports"], function (__exports__) {
__exports__.default = null;
});
define("bootbox", ["exports"], function (__exports__) {
__exports__.default = window.bootbox;
});

View File

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

View File

@ -1,6 +1,12 @@
(function (global) {
"use strict";
function aliasMethod(methodName) {
return function() {
return this[methodName].apply(this, arguments);
};
}
function empty(obj) {
var key;
for (key in obj) if (obj.hasOwnProperty(key)) return false;
@ -8,77 +14,156 @@
}
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,
hasBufferedChanges: false,
unknownProperty: function (key) {
var buffer = this.buffer;
return buffer && buffer.hasOwnProperty(key) ? buffer[key] : this._super(key);
hasChanges: Ember.computed.readOnly('hasBufferedChanges'),
applyChanges: function() {
return this.applyBufferedChanges(...arguments);
},
setUnknownProperty: function (key, value) {
if (!this.buffer) this.buffer = {};
discardChanges: function() {
return this.discardBufferedChanges(...arguments);
},
var buffer = this.buffer,
content = this.get('content'),
current = content && get(content, key),
previous = buffer.hasOwnProperty(key) ? buffer[key] : current;
init: function() {
this.initializeBuffer();
set(this, 'hasBufferedChanges', false);
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) {
delete buffer[key];
if (empty(buffer)) {
this.set('hasBufferedChanges', false);
set(this, 'hasBufferedChanges', false);
}
} else {
buffer[key] = value;
this.set('hasBufferedChanges', true);
set(this, 'hasBufferedChanges', true);
}
this.notifyPropertyChange(key);
notifyPropertyChange(content, key);
return value;
},
applyBufferedChanges: function() {
var buffer = this.buffer,
content = this.get('content'),
applyBufferedChanges: function(onlyTheseKeys) {
var props = getProperties(this, ['buffer', 'content']),
buffer = props.buffer,
content = props.content,
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]);
});
this.initializeBuffer(onlyTheseKeys);
if (empty(get(this, 'buffer'))) {
set(this, 'hasBufferedChanges', false);
}
this.buffer = {};
this.set('hasBufferedChanges', false);
},
discardBufferedChanges: function() {
var buffer = this.buffer,
content = this.get('content'),
discardBufferedChanges: function(onlyTheseKeys) {
var props = getProperties(this, ['buffer', 'content']),
buffer = props.buffer,
content = props.content,
key;
for (key in buffer) {
if (!buffer.hasOwnProperty(key)) continue;
delete buffer[key];
this.notifyPropertyChange(key);
this.initializeBuffer(onlyTheseKeys);
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
if (typeof module !== 'undefined' && module.exports) {
module.exports = BufferedProxy;
} 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;
});
} else {
global.BufferedProxy = BufferedProxy;
}
}(this));