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('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.
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):
or
However none of this works, because filters passed like that have to be loaded (via
Aria.load
) before proceeding further. The issue is thataddFilter
, 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 viaAria.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: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