beauby / jsonapi-datastore

JavaScript client-side JSON API data handling made easy.
MIT License
195 stars 40 forks source link

jsonapi-datastore does not work with requirejs #20

Open theirishpenguin opened 8 years ago

theirishpenguin commented 8 years ago

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 commented 8 years ago

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

var JsonApiDataStore = require("JsonApiDataStore").JsonApiDataStore;
beauby commented 8 years ago

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?

berlincount commented 8 years ago

15 & #16 address this as well.

theirishpenguin commented 8 years ago

@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?

berlincount commented 8 years ago

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

beauby commented 7 years ago

Is this fixed?

theirishpenguin commented 7 years ago

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.