2018-10-19 15:17:02 +00:00
|
|
|
import Service from '@ember/service';
|
|
|
|
import Evented from '@ember/object/evented';
|
|
|
|
const buffer = {};
|
|
|
|
export default Service.extend(Evented, {
|
|
|
|
// TODO: Consider renaming this and/or
|
|
|
|
// `delete`ing the buffer (but not the DOM element)
|
|
|
|
// flush should flush, but maybe being able to re-flush
|
|
|
|
// after you've flushed could be handy
|
|
|
|
flush: function(name) {
|
|
|
|
return buffer[name];
|
|
|
|
},
|
|
|
|
add: function(name, dom) {
|
|
|
|
this.trigger('add', dom);
|
2019-05-08 09:01:26 +00:00
|
|
|
if (typeof buffer[name] === 'undefined') {
|
|
|
|
buffer[name] = [];
|
|
|
|
}
|
|
|
|
buffer[name].push(dom);
|
2018-10-19 15:17:02 +00:00
|
|
|
return dom;
|
|
|
|
},
|
|
|
|
remove: function(name) {
|
2019-04-08 10:18:55 +00:00
|
|
|
if (typeof buffer[name] !== 'undefined') {
|
2019-05-08 09:01:26 +00:00
|
|
|
buffer[name].forEach(function(item) {
|
|
|
|
item.remove();
|
|
|
|
});
|
2019-04-08 10:18:55 +00:00
|
|
|
delete buffer[name];
|
|
|
|
}
|
2018-10-19 15:17:02 +00:00
|
|
|
},
|
|
|
|
});
|