quirkey / sammy

Sammy is a tiny javascript framework built on top of jQuery, It's RESTful Evented Javascript.
http://sammyjs.org
MIT License
2.99k stars 384 forks source link

runRoute function (dead code) #254

Open aplicacionamedida opened 7 years ago

aplicacionamedida commented 7 years ago

I observed some dead code in the funciton runRoute():

          if (typeof(route.callback) === "function") {
            route.callback = [route.callback];
          }
          if (route.callback && route.callback.length) {
            i = -1;
            nextRoute = function() {
              i++;
              if (route.callback[i]) {
                returned = route.callback[i].apply(context,callback_args);
              } else if (app._onComplete && typeof(app._onComplete === "function")) {
                app._onComplete(context);
              }
            };
            callback_args.push(nextRoute);
            nextRoute();
          }

Variable "i" has no meaning, because a chain of callback is not well implemented.

For this reason, I think that this code should be deleted also:

        if (typeof(route.callback) === "function") {
            route.callback = [route.callback];
          }

Callback should be always a function. Never an array.

For this reason this code , also has to be changed:

    if (route.callback[i]) {