biril / backbone-faux-server

A framework for mocking up server-side persistence / processing for Backbone.js
MIT License
54 stars 11 forks source link

Faux Server with require.js #9

Closed artgladun closed 10 years ago

artgladun commented 10 years ago

Hi, I have some model structure in ma project. Each of this model need to fetch or save and I decided to use fake, faux-server. In my projekt i also use a require.js and here I have a problem. When I define some mocks of faux-server (more then one) - only the last always run, the previous not.

I tried to use shim in requrie to have a one global fauxServer for each mocks but it doesnt work.

shim: { 
    fauxServer: { 
        deps['backbone'], 
        exports: 'fauxServer' 
   }
}
biril commented 10 years ago

Hey @czeczeko, I begun writing a small example app for your purposes but run into some problematic behaviour which I was not aware of. (Thanks for bringing that to my attention). I will do a fix and get back to you with an example (for use with requirejs) later on today.

biril commented 10 years ago

@czeczeko

version 9.3 (the latest as of now), should fix your problem.

As for loading fauxServer with require.js there should be no need to shim it - it is exported as an AMD module. In turn, it depends on 'underscore' and 'backbone' being available as AMD modules which means that you either go with the AMD versions and use a config such as

require.config({
    baseUrl: "myapp/",
    paths: {
        "underscore": "mylibs/underscore",
        "backbone": "mylibs/backbone"
    }
});

or that you shim them (but not fauxServer) as described in requirejs docs.

Please let me know if that works out ok.

artgladun commented 10 years ago

Thank you! I updated your lib and it is solved the problem.

biril commented 10 years ago

Nice - thanks for the heads up.