]> git.gir.st - VimFx.git/blob - extension/lib/public.coffee
Merge pull request #561 from cbertoldi/develop
[VimFx.git] / extension / lib / public.coffee
1 ###
2 # Copyright Simon Lydell 2015.
3 #
4 # This file is part of VimFx.
5 #
6 # VimFx is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # VimFx is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with VimFx. If not, see <http://www.gnu.org/licenses/>.
18 ###
19
20 # This file provides VimFx’s public API (defined in api.coffee) for public
21 # consumption. It is kept as short as possible on purpose to reduce the need to
22 # update it. When VimFx updates, consumers of this module do not get updates to
23 # this module until the next Firefox restart.
24
25 EXPORTED_SYMBOLS = ['getAPI']
26
27 # Once VimFx has been installed, this file will be available on the file system,
28 # and the `api_url` pref will be available in Firefox’s prefs system. That’s all
29 # that is needed to `Cu.import` this file, regardless of whether VimFx has
30 # loaded or not. When VimFx _is_ loaded, `_invokeCallback` (which requires
31 # access to the global `VimFx` instance) is set by main.coffee.
32 _invokeCallback = null
33
34 # All requests for the API are stored here.
35 _callbacks = []
36
37 # All callbacks are always stored, in case they need to be re-run in the future.
38 # If main.coffee already has set `_invokeCallback` then run it. Otherwise let
39 # main.coffee take care of the queue in `_callbacks` when it loads.
40 getAPI = (callback) ->
41 _callbacks.push(callback)
42 _invokeCallback?(callback)
Imprint / Impressum