marcuswestin / store.js

Cross-browser storage for all use cases, used across the web.
MIT License
14.01k stars 1.33k forks source link

Using with require.JS #272

Open youradds opened 6 years ago

youradds commented 6 years ago

Hi,

I'm trying to get this going with require.js. I have the following:

// Configure loading modules from the lib directory,
// except 'app' ones,
requirejs.config({
    "baseUrl": "js/lib",
    "paths": {
      "common-functions": "common-functions",
      "domReady": "domready",
      "storage": "storage",
    },
    "shim": {
        "common-functions": {
            //"deps": ["jquery","datepicker","domReady"]
            "deps": ["storage","domReady"]
        }
    }

});

require(['storage'], function(store) {
    require(['domReady','common-functions'], function(domReady){
      store.set("foo","bar"); // this works ok!
    }, function (err) {
      console.log("Error: " + err)
    });
});

It works like this as "store" is available - however, if I were to use it in the test common-functions.js, I get an undefined value for store:

common-functions.js =>

store.set("foo","bar");

ReferenceError: store is not defined

Do I need to wrap common-functions.js with something to make it work?