Skip to main content
added 49 characters in body
Source Link

You would possibly be better off with login, share, publish and navigate as promise-returning worker functions:

var login = function() { return isLoggedIn ? null : facebookActions.login(); }
var share = function() { return scope.sharingActions.shareOnFacebook(); };
var publish = function() { return scope.model.publish() };
var navigate = function() { return app.router.navigateToStories() };

Now you can sequence these workers with .then() as follows (or similar) :

var rootPromise = $.Deferred().resolve().promise();

if (noViews) {
    if(hasEditPermissions || !isLoggedIn) {
        rootPromise.then(login).then(share).then(publish).then(navigate);
    }
    else {
        rootPromise.then(share).then(navigate);
    }
}
else if(hasEditPermissions) {
    rootPromise.then(share).then(navigate);
}

Notes:

  • rootPromise isn't strictly necessary but keeps rest of the code tidier, particularly login().

  • login() returns null if already logged in, allowing the calling logic to be slightly simpler.

  • The whole thing may simplify further depending largelyin part on the relationship between hasEditPermissions and isLoggedIn (See other answers for suggestions).

You would possibly be better off with login, share, publish and navigate as promise-returning worker functions:

var login = function() { return isLoggedIn ? null : facebookActions.login(); }
var share = function() { return scope.sharingActions.shareOnFacebook(); };
var publish = function() { return scope.model.publish() };
var navigate = function() { return app.router.navigateToStories() };

Now you can sequence these workers with .then() as follows :

var rootPromise = $.Deferred().resolve().promise();

if (noViews) {
    if(hasEditPermissions || !isLoggedIn) {
        rootPromise.then(login).then(share).then(publish).then(navigate);
    }
    else {
        rootPromise.then(share).then(navigate);
    }
}
else if(hasEditPermissions) {
    rootPromise.then(share).then(navigate);
}

Notes:

  • rootPromise isn't strictly necessary but keeps rest of the code tidier, particularly login().

  • login() returns null if already logged in, allowing the calling logic to be slightly simpler.

  • The whole thing may simplify further depending largely on the relationship between hasEditPermissions and isLoggedIn.

You would possibly be better off with login, share, publish and navigate as promise-returning worker functions:

var login = function() { return isLoggedIn ? null : facebookActions.login(); }
var share = function() { return scope.sharingActions.shareOnFacebook(); };
var publish = function() { return scope.model.publish() };
var navigate = function() { return app.router.navigateToStories() };

Now you can sequence these workers with .then() as follows (or similar) :

var rootPromise = $.Deferred().resolve().promise();

if (noViews) {
    if(hasEditPermissions || !isLoggedIn) {
        rootPromise.then(login).then(share).then(publish).then(navigate);
    }
    else {
        rootPromise.then(share).then(navigate);
    }
}
else if(hasEditPermissions) {
    rootPromise.then(share).then(navigate);
}

Notes:

  • rootPromise isn't strictly necessary but keeps rest of the code tidier, particularly login().

  • login() returns null if already logged in, allowing the calling logic to be slightly simpler.

  • The whole thing may simplify further depending in part on the relationship between hasEditPermissions and isLoggedIn (See other answers for suggestions).

deleted 1 characters in body
Source Link

I think youYou would possibly be better off with login, share, publish and navigate as promise-returning worker functions:

var login = function() { return isLoggedIn ? null : facebookActions.login(); }
var share = function() { return scope.sharingActions.shareOnFacebook(); };
var publish = function() { return scope.model.publish() };
var navigate = function() { return app.router.navigateToStories() };

Now you can sequence these workers with .then() as follows :

var rootPromise = $.Deferred().resolve().promise();

if (noViews) {
    if(hasEditPermissions || !isLoggedIn) {
        rootPromise.then(login).then(share).then(publish).then(navigate);
    }
    else {
        rootPromise.then(share).then(navigate);
    }
}
else if(hasEditPermissions) {
    rootPromise.then(share).then(navigate);
}

Notes:

  • rootPromise isn't strictly necessary but keeps rest of the code tidier, particularly login().

  • login() returns null if already logged in, allowing the calling logic to be slightly simpler.

  • The whole thing may simplify further depending largely on the relationship between hasEditPermissions and isLoggedIn.

I think you would be better off with login, share, publish and navigate as promise-returning worker functions:

var login = function() { return isLoggedIn ? null : facebookActions.login(); }
var share = function() { return scope.sharingActions.shareOnFacebook(); };
var publish = function() { return scope.model.publish() };
var navigate = function() { return app.router.navigateToStories() };

Now you can sequence these workers with .then() as follows :

var rootPromise = $.Deferred().resolve().promise();

if (noViews) {
    if(hasEditPermissions || !isLoggedIn) {
        rootPromise.then(login).then(share).then(publish).then(navigate);
    }
    else {
        rootPromise.then(share).then(navigate);
    }
}
else if(hasEditPermissions) {
    rootPromise.then(share).then(navigate);
}

Notes:

  • rootPromise isn't strictly necessary but keeps rest of the code tidier, particularly login().

  • login() returns null if already logged in, allowing the calling logic to be slightly simpler.

  • The whole thing may simplify further depending largely on the relationship between hasEditPermissions and isLoggedIn.

You would possibly be better off with login, share, publish and navigate as promise-returning worker functions:

var login = function() { return isLoggedIn ? null : facebookActions.login(); }
var share = function() { return scope.sharingActions.shareOnFacebook(); };
var publish = function() { return scope.model.publish() };
var navigate = function() { return app.router.navigateToStories() };

Now you can sequence these workers with .then() as follows :

var rootPromise = $.Deferred().resolve().promise();

if (noViews) {
    if(hasEditPermissions || !isLoggedIn) {
        rootPromise.then(login).then(share).then(publish).then(navigate);
    }
    else {
        rootPromise.then(share).then(navigate);
    }
}
else if(hasEditPermissions) {
    rootPromise.then(share).then(navigate);
}

Notes:

  • rootPromise isn't strictly necessary but keeps rest of the code tidier, particularly login().

  • login() returns null if already logged in, allowing the calling logic to be slightly simpler.

  • The whole thing may simplify further depending largely on the relationship between hasEditPermissions and isLoggedIn.

Source Link

I think you would be better off with login, share, publish and navigate as promise-returning worker functions:

var login = function() { return isLoggedIn ? null : facebookActions.login(); }
var share = function() { return scope.sharingActions.shareOnFacebook(); };
var publish = function() { return scope.model.publish() };
var navigate = function() { return app.router.navigateToStories() };

Now you can sequence these workers with .then() as follows :

var rootPromise = $.Deferred().resolve().promise();

if (noViews) {
    if(hasEditPermissions || !isLoggedIn) {
        rootPromise.then(login).then(share).then(publish).then(navigate);
    }
    else {
        rootPromise.then(share).then(navigate);
    }
}
else if(hasEditPermissions) {
    rootPromise.then(share).then(navigate);
}

Notes:

  • rootPromise isn't strictly necessary but keeps rest of the code tidier, particularly login().

  • login() returns null if already logged in, allowing the calling logic to be slightly simpler.

  • The whole thing may simplify further depending largely on the relationship between hasEditPermissions and isLoggedIn.