mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 09:36:19 -05:00
withPluginApi
means you don't have to check for null.
This commit is contained in:
parent
3ea1f88cdc
commit
3a78321c63
4 changed files with 22 additions and 14 deletions
|
@ -1,13 +1,13 @@
|
|||
import highlightSyntax from 'discourse/lib/highlight-syntax';
|
||||
import lightbox from 'discourse/lib/lightbox';
|
||||
import { getPluginApi } from 'discourse/lib/plugin-api';
|
||||
import { withPluginApi } from 'discourse/lib/plugin-api';
|
||||
|
||||
export default {
|
||||
name: "post-decorations",
|
||||
initialize() {
|
||||
const api = getPluginApi('0.1');
|
||||
|
||||
api.decorateCooked(highlightSyntax);
|
||||
api.decorateCooked(lightbox);
|
||||
withPluginApi('0.1', api => {
|
||||
api.decorateCooked(highlightSyntax);
|
||||
api.decorateCooked(lightbox);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
|
@ -67,13 +67,20 @@ class PluginApi {
|
|||
}
|
||||
|
||||
let _pluginv01;
|
||||
export function getPluginApi(version) {
|
||||
function getPluginApi(version) {
|
||||
if (version === "0.1") {
|
||||
if (!_pluginv01) {
|
||||
_pluginv01 = new PluginApi(version, Discourse.__container__);
|
||||
}
|
||||
return _pluginv01;
|
||||
} else {
|
||||
throw `Plugin API v${version} is not supported`;
|
||||
console.warn(`Plugin API v${version} is not supported`);
|
||||
}
|
||||
}
|
||||
|
||||
export function withPluginApi(version, cb) {
|
||||
const api = getPluginApi(version);
|
||||
if (api) {
|
||||
cb(api);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import { getPluginApi } from 'discourse/lib/plugin-api';
|
||||
import { withPluginApi } from 'discourse/lib/plugin-api';
|
||||
|
||||
export default {
|
||||
name: "apply-details",
|
||||
|
||||
initialize() {
|
||||
const api = getPluginApi('0.1');
|
||||
api.decorateCooked($elem => $("details", $elem).details());
|
||||
withPluginApi('0.1', api => {
|
||||
api.decorateCooked($elem => $("details", $elem).details());
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
import { getPluginApi } from 'discourse/lib/plugin-api';
|
||||
import { withPluginApi } from 'discourse/lib/plugin-api';
|
||||
|
||||
export default {
|
||||
name: "apply-lazyYT",
|
||||
initialize() {
|
||||
const api = getPluginApi('0.1');
|
||||
api.decorateCooked($elem => $('.lazyYT', $elem).lazyYT());
|
||||
withPluginApi('0.1', api => {
|
||||
api.decorateCooked($elem => $('.lazyYT', $elem).lazyYT());
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue