From 63cda2262307d43160de0a84d538a646cd288723 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Tue, 16 Feb 2016 16:43:59 -0500 Subject: [PATCH] Upgrade `withPluginApi` to support non-api callbacks --- .../discourse/lib/plugin-api.js.es6 | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/discourse/lib/plugin-api.js.es6 b/app/assets/javascripts/discourse/lib/plugin-api.js.es6 index f5d66d738a6..5a700db5f2a 100644 --- a/app/assets/javascripts/discourse/lib/plugin-api.js.es6 +++ b/app/assets/javascripts/discourse/lib/plugin-api.js.es6 @@ -16,7 +16,29 @@ export function decorateCooked(container, cb) { decorate(container.lookupFactory('view:user-stream'), 'didInsertElement', cb); } -// Will be backported so plugins in the new format will not raise errors -export function withPluginApi(version) { +// This is backported so plugins in the new format will not raise errors +// +// To upgrade your plugin for backwards compatibility, you can add code in this +// form: +// +// function newApiCode(api) { +// // api.xyz(); +// } +// +// function oldCode() { +// // your pre-PluginAPI code goes here. You will be able to delete this +// // code once the `PluginAPI` has been rolled out to all versions of +// // Discourse you want to support. +// } +// +// // `newApiCode` will use API version 0.1, if no API support then +// // `oldCode` will be called +// withPluginApi('0.1', newApiCode, { noApi: oldCode }); +// +export function withPluginApi(version, apiCodeCallback, opts) { console.warn(`Plugin API v${version} is not supported`); + + if (opts && opts.noApi) { + return opts.noApi(); + } }