From c6456f5c3e50e3484f65fbafbe400d1ac2aa72dc Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Tue, 16 Feb 2016 16:22:35 -0500 Subject: [PATCH] Provide an option callback to the API --- .../javascripts/discourse/lib/plugin-api.js.es6 | 13 +++++++++++-- 1 file changed, 11 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 3f9d17c4a01..c429d6b4a2a 100644 --- a/app/assets/javascripts/discourse/lib/plugin-api.js.es6 +++ b/app/assets/javascripts/discourse/lib/plugin-api.js.es6 @@ -78,9 +78,18 @@ function getPluginApi(version) { } } -export function withPluginApi(version, cb) { +/** + * withPluginApi(version, apiCode, noApi) + * + * Helper to version our client side plugin API. Pass the version of the API that your + * plugin is coded against. If that API is available, the `apiCodeCallback` function will + * be called with the `PluginApi` object. +*/ +export function withPluginApi(version, apiCodeCallback, opts) { + opts = opts || {}; + const api = getPluginApi(version); if (api) { - cb(api); + return apiCodeCallback(api); } }