jsonapi-datastore icon indicating copy to clipboard operation
jsonapi-datastore copied to clipboard

jsonapi-datastore does not work with requirejs

Open theirishpenguin opened this issue 9 years ago • 7 comments

I'm using jsonapi-datastore (master branch at commit 12dc63e) via requirejs and I have to implement the following workaround to get it to work in jsonapi-datastore/dist/jsonapi-datastore.js...

if ( typeof define === "function" && define.amd ) {                             
  define(function (require, exports, module) {                                  
    module.exports = {                                                          
      JsonApiDataStore: JsonApiDataStore,                                       
      JsonApiDataStoreModel: JsonApiDataStoreModel                              
    };                                                                          
  });                                                                           
}

This hack is based on http://stackoverflow.com/a/29655291.

I'm not sure if this is the best solution to this problem so I haven't put it in a PR. Would adding this block to the end of jsonapi-datastore.js make sense?

theirishpenguin avatar Dec 14 '15 11:12 theirishpenguin

P.S. With the above workaround I also have to change my require slightly to be...

var JsonApiDataStore = require("JsonApiDataStore").JsonApiDataStore;

theirishpenguin avatar Dec 14 '15 12:12 theirishpenguin

Hi @theirishpenguin, thanks for the feedback – I've been fairly busy lately. If you find some time, would you mind issuing a PR to fix the situation?

beauby avatar Mar 10 '16 17:03 beauby

#15 & #16 address this as well.

berlincount avatar Mar 13 '16 03:03 berlincount

@beauby Ya, happy to PR it. Or @berlincount if this is better solved using #15 and #16 then I will not bother PR'ing this?

theirishpenguin avatar Mar 14 '16 11:03 theirishpenguin

well, they are closed in master - verify whether they fix this for you :)

berlincount avatar Mar 14 '16 11:03 berlincount

Is this fixed?

beauby avatar Oct 21 '16 01:10 beauby

Hi, sorry somehow I missed your last message @berlincount.

@beauby, thanks for the follow up. I've just retested master but when I try do the require with...

var JsonApiDataStore = require("JsonApiDataStore");

... I see that JsonApiDataStore is undefined and this causes and error later in the code when I try to instantiate a JsonApiDataStore instance.

I've since moved away from using requirejs on my main projects so this issue is less important for me than it used to be. However I am happy to help debug this.

theirishpenguin avatar Oct 24 '16 11:10 theirishpenguin