seriema / angular-apimock

Automatically route your API calls to static JSON files, for hiccup free front–end development.
johansson.jp/angular-apimock
MIT License
65 stars 8 forks source link

Make the function, which decides whether to apply mocking, configurable #5

Closed iPirat closed 10 years ago

iPirat commented 10 years ago

Make the function, which decides whether to apply mocking, configurable a la

.config({
    mockDataPath: '/mock_data',
    apiPath: '/api',
    doMock: function(){ 
        var myresult = /* implement some custom check */;
        return myresult; 
    }
});

the default should be the "old" behaviour

seriema commented 10 years ago

Ah! Awesome idea!! I'll include that in the next version.

seriema commented 10 years ago

It's now a step closer, you can override shouldReplace, replacePath and isMocking. The first two are a bit specific to this implementation (replace /api with /mock_data paths) so I'm thinking about how to make it cleaner. It's hard to make it more dynamic without it turning into "why not just make your own httpInterceptor?". Need to write docs for this though.

seriema commented 10 years ago

After several attempts it's just too dependent on everything else. It's not really possible to configure just one part without changing everything else. So we're back at just configuring the paths, but I've added a Q in the FAQ that shows how you can create your own httpInterceptor which is what apiMock does.