Search code examples
firefoxfirefox-addonrequirejsfirefox-addon-sdkcommonjs

Object persistence across modules on Firefox


I have developed an extension that runs on Firefox's Addon SDK (v1.10). I am now trying to modularize more the code stored in the background page (called 'main.js' as default).

PROBLEM

Is there a way to create an SDK module that is not frozen? I need to create a module that contains data that should persist in itself and be accessible from other modules when that module is 'required()' (loaded) into another module.

As of now, I accomplish this by using either Firefox's preferences or local storage to persist the state of the objects I need across modules. However, I feel like this method is a 'hack' way of doing it and there should be a better way of doing so.


Solution

  • If you create simple CommonJS modules, any data exported by the module is mutable and shareable. For instance, check out this basic example:

    https://github.com/canuckistani/jp-shared-data-module