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

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.

diff --git a/app/assets/javascripts/discourse-shims.js b/app/assets/javascripts/discourse-shims.js
index bf4765a..b63d4a6 100644
--- a/app/assets/javascripts/discourse-shims.js
+++ b/app/assets/javascripts/discourse-shims.js
@@ -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;
 });
diff --git a/app/assets/javascripts/discourse/app/controllers/reorder-categories.js b/app/assets/javascripts/discourse/app/controllers/reorder-categories.js
index 333108e..47da67b 100644
--- a/app/assets/javascripts/discourse/app/controllers/reorder-categories.js
+++ b/app/assets/javascripts/discourse/app/controllers/reorder-categories.js
@@ -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"),
diff --git a/app/assets/javascripts/discourse/app/mixins/buffered-content.js b/app/assets/javascripts/discourse/app/mixins/buffered-content.js
index 2b13f7d..92b44f1 100644
--- a/app/assets/javascripts/discourse/app/mixins/buffered-content.js
+++ b/app/assets/javascripts/discourse/app/mixins/buffered-content.js
@@ -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),
       });
     }),
diff --git a/vendor/assets/javascripts/buffered-proxy.js b/vendor/assets/javascripts/buffered-proxy.js
index a26ec63..24f8243 100644
--- a/vendor/assets/javascripts/buffered-proxy.js
+++ b/vendor/assets/javascripts/buffered-proxy.js
@@ -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({
-    buffer: null,
+  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);
+    },
+
+    initializeBuffer: function(onlyTheseKeys) {
+      if(isArray(onlyTheseKeys) && !empty(onlyTheseKeys)) {
+        onlyTheseKeys.forEach((key) => delete this.buffer[key]);
+      }
+      else {
+        set(this, 'buffer', Object.create(null));
+      }
+    },
 
-      if (previous === value) return;
+    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);
+    },
+

[... diff too long, it was truncated ...]

GitHub sha: eb6a6446

This commit appears in #13227 which was approved by eviltrout. It was merged by CvX.