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

Syncher Tunnel Filters #291

Open
wants to merge 8 commits into
base: v2
Choose a base branch
from
Open

Syncher Tunnel Filters #291

wants to merge 8 commits into from

Conversation

adam-26
Copy link
Contributor

@adam-26 adam-26 commented Jun 16, 2015

PR for #189 and #219.

To add a tunnel filter: LAZO.app.addTunnelFilter([tunnelFilter]);

Tunnel filter interface:

var tunnelFilter = {
    onRequest: function (method, modelOrArgs, params, options) {
        options.stop({ statusCode: 500, error: 'Something went wrong' });
        options.continue(method, modelOrArgs, params);
    },

    onSuccess: function (model, response, options) {
        options.stop(model, response);
        options.continue(model, response);
    },

    onError: function (model, response, options) {
        options.stop(model, response);
        options.continue(model, response);
    }
};

Instead of using the standard success() and error(), I opted to instead use continue() and stop() because I think it better shows the intent. Also, using success() and error() in the onSuccess() and onError() handlers was confusing.

When stop() is called in the onRequest() handler, the syncher request will not be processed. The tunnel filters onError() handlers will be executed.
When stop() is called in onSuccess()/onError() handlers, no more tunnel filters will be executed.

To understand the order the filters are processed, see this example:

var tunnelFilter1 = {
    onRequest: function (method, modelOrArgs, params, options) {
        LAZO.logger.info('onRequest1');
        options.continue(method, modelOrArgs, params);
    },

    onSuccess: function (model, response, options) {
        LAZO.logger.info('onSuccess1');
        options.continue(model, response);
    }
};

var tunnelFilter2 = {
    onRequest: function (method, modelOrArgs, params, options) {
        LAZO.logger.info('onRequest2');
        options.continue(method, modelOrArgs, params);
    },

    onSuccess: function (model, response, options) {
        LAZO.logger.info('onSuccess2');
        options.continue(model, response);
    }
};

LAZO.app.addTunnelFilter(tunnelFilter1);
LAZO.app.addTunnelFilter(tunnelFilter2);

// onRequest1
// onRequest2
// [Syncher function executed here]
// onSuccess2
// onSuccess1

Let me know if you have any questions. Adam.

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

Successfully merging this pull request may close these issues.

1 participant