John Cowen 067ed448e3 ui: Amends to the data-sink service/component (#7740)
1. Fix conditional typo
2. Code style changes
3. Don't use URL for parsing, Safari only likes http like URLs
2020-05-12 17:14:37 +00:00

25 lines
660 B
JavaScript

import Service, { inject as service } from '@ember/service';
import { setProperties } from '@ember/object';
export default Service.extend({
settings: service('settings'),
prepare: function(sink, data, instance = {}) {
if (data === null || data === '') {
return instance;
}
return setProperties(instance, data);
},
persist: function(sink, instance) {
const slug = sink.split(':').pop();
const repo = this.settings;
return repo.persist({
[slug]: instance,
});
},
remove: function(sink, instance) {
const slug = sink.split(':').pop();
const repo = this.settings;
return repo.delete(slug);
},
});