This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/mixins/buffered-content.js.es6

30 lines
735 B
JavaScript

import EmberObjectProxy from "@ember/object/proxy";
import Mixin from "@ember/object/mixin";
import { computed } from "@ember/object";
/* global BufferedProxy: true */
export function bufferedProperty(property) {
const mixin = {
buffered: computed(property, function() {
return EmberObjectProxy.extend(BufferedProxy).create({
content: this.get(property)
});
}),
rollbackBuffer: function() {
this.buffered.discardBufferedChanges();
},
commitBuffer: function() {
this.buffered.applyBufferedChanges();
}
};
// It's a good idea to null out fields when declaring objects
mixin.property = null;
return Mixin.create(mixin);
}
export default bufferedProperty("content");