PluginAPI for more stable backwards compatibility going forward

This commit is contained in:
Robin Ward
2016-02-12 15:46:36 -05:00
parent 81ee8f760a
commit 9b8871d7dd
4 changed files with 41 additions and 19 deletions

View File

@ -8,8 +8,31 @@ function decorate(klass, evt, cb) {
klass.reopen(mixin);
}
export function decorateCooked(container, cb) {
addDecorator(cb);
decorate(ComposerEditor, 'previewRefreshed', cb);
decorate(container.lookupFactory('view:user-stream'), 'didInsertElement', cb);
export function decorateCooked() {
console.warn('`decorateCooked` has been removed. Use `getPluginApi(version).decorateCooked` instead');
}
class PluginApi {
constructor(version, container) {
this.version = version;
this.container = container;
}
decorateCooked(cb) {
addDecorator(cb);
decorate(ComposerEditor, 'previewRefreshed', cb);
decorate(this.container.lookupFactory('view:user-stream'), 'didInsertElement', cb);
}
}
let _pluginv01;
export function getPluginApi(version) {
if (version === "0.1") {
if (!_pluginv01) {
_pluginv01 = new PluginApi(version, Discourse.__container__);
}
return _pluginv01;
}
}