Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IOFilters are not taken into account by Aria.load unless specific syntax is used #65

Open
jakub-g opened this issue Feb 20, 2014 · 0 comments

Comments

@jakub-g
Copy link
Collaborator

jakub-g commented Feb 20, 2014

http://ariatemplates.com/usermanual/latest/filters

There are two issues regarding this article.

First, there's no sample about how to redirect to a static file (yeah it's in the api docs though this is pretty useful IMO so should be in the usermanual too).

This is mostly useful for mocking server interactions, i.e. return static JSON instead of contacting the backend. (i.e. usages of asyncRequest, submitJsonRequest etc.)

However, another thing I though it could be useful for is in a test, to redirect certain classpath to another classpath temporarily (well it could be done with URL maps too, but someone might come up with the same idea as me):

aria.core.IOFiltersMgr.addFilter({
    classpath : "test.aria.core.test.IOFilterSample",
    initArgs : {
        onRequest : function (req) {
            if (aria.utils.String.endsWith(req.url, "FooClass.js")) {
                this.redirectToFile(req, "myapp.classes.FooClassMock.js");
            }
        }
    }
});

or

aria.core.IOFiltersMgr.addFilter('myapp.classes.MyIOFilter'); // it has `onRequest` as above

However none of this works, because filters passed like that have to be loaded (via Aria.load) before proceeding further. The issue is that addFilter, when passed a string or an object with classpath, doesn't load the filters right away, they're loaded just before a request. When there's a request via Aria.load to load some class, the missing filters are not instantiated due to [1].

The bottom line is, the only way to have Aria.load take a filter into account, is to create an instance of it manually, and only then add that filter:

var myFilter = new myapp.classes.MyIOFilter();
aria.core.IOFiltersMgr.addFilter(myFilter);

Since there's an instance passed, this filter is applied right away (loading is not deferred until before-the-request).

This should be documented in the usermanual as an edge case.

[1] https://github.com/ariatemplates/ariatemplates/blob/v1.4.16/src/aria/core/IOFiltersMgr.js#L314

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant