Skip to content

Commit

Permalink
Fixed minor issue with changing $state.current a bit to soon for inte…
Browse files Browse the repository at this point in the history
…rnal use cases.
  • Loading branch information
jeme committed Jan 12, 2015
1 parent 747a664 commit 07d1cc9
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 27 deletions.
30 changes: 22 additions & 8 deletions build/angular-routing.js
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,19 @@ function $PipelineProvider() {
return { name: name, stage: stage };
}

this.replace = function (name, stage) {
var index = indexOf(name);
if (index === -1) {
throw new Error("No stages was registered under the name '" + name + "', use insert instead.");
}

stage = wrap(name, stage);
stages[index] = stage;
stagesMap[name] = stage;

return self;
};

this.append = function (name, stage) {
stage = wrap(name, stage);
if (map(name, stage)) {
Expand All @@ -903,7 +916,7 @@ function $PipelineProvider() {
// - .in().insert('x').after('y');
// - .after().insert('x').last();
// - .after().insert('x').first();
//
// - .replace()
//
//
this.insert = function (name, stage) {
Expand Down Expand Up @@ -2214,7 +2227,7 @@ var $StateProvider = [
*/
var urlbuilder = new StateUrlBuilder($route);

var current = root, $state = {
var currentForUrls = extend(root.self, { $params: buildParams() }), current = root, $state = {
// NOTE: root should not be used in general, it is exposed for testing purposes.
root: root,
current: extend(root.self, { $params: buildParams() }),
Expand All @@ -2241,24 +2254,24 @@ var $StateProvider = [
},
// State Params Base
url: function (arg1, arg2, arg3) {
var target = current;
var target = current, cs = currentForUrls;

//Note: No params means we will use current state as both target and source.
if (arguments.length === 0) {
// current, target, params?, base?
return urlbuilder.buildUrl($state.current, target, undefined, undefined);
return urlbuilder.buildUrl(cs, target, undefined, undefined);
}

//Note: One param means we either got a target state or was asked to use base.
if (arguments.length === 1) {
if (isBool(arg1)) {
// current, target, params?, base?
return urlbuilder.buildUrl($state.current, target, undefined, arg1);
return urlbuilder.buildUrl(cs, target, undefined, arg1);
} else {
target = browser.resolve(current, toName(arg1), false);

// current, target, params?, base?
return urlbuilder.buildUrl($state.current, target, undefined, undefined);
return urlbuilder.buildUrl(cs, target, undefined, undefined);
}
}

Expand All @@ -2268,10 +2281,10 @@ var $StateProvider = [

if (isBool(arg2)) {
// current, target, params?, base?
return urlbuilder.buildUrl($state.current, target, undefined, arg2);
return urlbuilder.buildUrl(cs, target, undefined, arg2);
} else {
// current, target, params?, base?
return urlbuilder.buildUrl($state.current, target, arg2, arg3);
return urlbuilder.buildUrl(cs, target, arg2, arg3);
}
},
is: function (state, params) {
Expand Down Expand Up @@ -2364,6 +2377,7 @@ var $StateProvider = [
running.promise.then(function () {
current = changes.to;
defered.resolve(current);
currentForUrls = $state.current;
}).catch(defered.reject);
return defered.promise.finally(function () {
inProgress = false;
Expand Down
2 changes: 1 addition & 1 deletion build/angular-routing.min.js

Large diffs are not rendered by default.

30 changes: 22 additions & 8 deletions gh-pages/assets/scripts/angular-routing/impl/angular-routing.js
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,19 @@ function $PipelineProvider() {
return { name: name, stage: stage };
}

this.replace = function (name, stage) {
var index = indexOf(name);
if (index === -1) {
throw new Error("No stages was registered under the name '" + name + "', use insert instead.");
}

stage = wrap(name, stage);
stages[index] = stage;
stagesMap[name] = stage;

return self;
};

this.append = function (name, stage) {
stage = wrap(name, stage);
if (map(name, stage)) {
Expand All @@ -903,7 +916,7 @@ function $PipelineProvider() {
// - .in().insert('x').after('y');
// - .after().insert('x').last();
// - .after().insert('x').first();
//
// - .replace()
//
//
this.insert = function (name, stage) {
Expand Down Expand Up @@ -2214,7 +2227,7 @@ var $StateProvider = [
*/
var urlbuilder = new StateUrlBuilder($route);

var current = root, $state = {
var currentForUrls = extend(root.self, { $params: buildParams() }), current = root, $state = {
// NOTE: root should not be used in general, it is exposed for testing purposes.
root: root,
current: extend(root.self, { $params: buildParams() }),
Expand All @@ -2241,24 +2254,24 @@ var $StateProvider = [
},
// State Params Base
url: function (arg1, arg2, arg3) {
var target = current;
var target = current, cs = currentForUrls;

//Note: No params means we will use current state as both target and source.
if (arguments.length === 0) {
// current, target, params?, base?
return urlbuilder.buildUrl($state.current, target, undefined, undefined);
return urlbuilder.buildUrl(cs, target, undefined, undefined);
}

//Note: One param means we either got a target state or was asked to use base.
if (arguments.length === 1) {
if (isBool(arg1)) {
// current, target, params?, base?
return urlbuilder.buildUrl($state.current, target, undefined, arg1);
return urlbuilder.buildUrl(cs, target, undefined, arg1);
} else {
target = browser.resolve(current, toName(arg1), false);

// current, target, params?, base?
return urlbuilder.buildUrl($state.current, target, undefined, undefined);
return urlbuilder.buildUrl(cs, target, undefined, undefined);
}
}

Expand All @@ -2268,10 +2281,10 @@ var $StateProvider = [

if (isBool(arg2)) {
// current, target, params?, base?
return urlbuilder.buildUrl($state.current, target, undefined, arg2);
return urlbuilder.buildUrl(cs, target, undefined, arg2);
} else {
// current, target, params?, base?
return urlbuilder.buildUrl($state.current, target, arg2, arg3);
return urlbuilder.buildUrl(cs, target, arg2, arg3);
}
},
is: function (state, params) {
Expand Down Expand Up @@ -2364,6 +2377,7 @@ var $StateProvider = [
running.promise.then(function () {
current = changes.to;
defered.resolve(current);
currentForUrls = $state.current;
}).catch(defered.reject);
return defered.promise.finally(function () {
inProgress = false;
Expand Down

Large diffs are not rendered by default.

15 changes: 14 additions & 1 deletion src/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,19 @@ function $PipelineProvider() {
return { name: name, stage: stage };
}

this.replace = function(name, stage) {
var index = indexOf(name);
if (index === -1) {
throw new Error("No stages was registered under the name '" + name + "', use insert instead.");
}

stage = wrap(name, stage);
stages[index] = stage;
stagesMap[name] = stage;

return self;
};

this.append = function (name, stage) {
stage = wrap(name, stage);
if (map(name, stage)) {
Expand All @@ -64,7 +77,7 @@ function $PipelineProvider() {
// - .in().insert('x').after('y');
// - .after().insert('x').last();
// - .after().insert('x').first();
//
// - .replace()
//
//
this.insert = function (name, stage) {
Expand Down
17 changes: 9 additions & 8 deletions src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ var $StateProvider = [<any>'$routeProvider', '$stateTransitionProvider', '$pipel
}
return this;
};

function registerState(fullname: string, state: dotjem.routing.IState) {
StateRules.validateName(fullname);

Expand Down Expand Up @@ -532,7 +532,7 @@ var $StateProvider = [<any>'$routeProvider', '$stateTransitionProvider', '$pipel

var urlbuilder = new StateUrlBuilder($route);

var
var currentForUrls = extend(root.self, { $params: buildParams() }),
current = root,
$state: any = {
// NOTE: root should not be used in general, it is exposed for testing purposes.
Expand Down Expand Up @@ -561,22 +561,22 @@ var $StateProvider = [<any>'$routeProvider', '$stateTransitionProvider', '$pipel
},
// State Params Base
url: function (arg1?, arg2?, arg3?) {
var target = current;
var target = current, cs = currentForUrls;
//Note: No params means we will use current state as both target and source.
if (arguments.length === 0) {
// current, target, params?, base?
return urlbuilder.buildUrl($state.current, target, undefined, undefined);
return urlbuilder.buildUrl(cs, target, undefined, undefined);
}

//Note: One param means we either got a target state or was asked to use base.
if (arguments.length === 1) {
if (isBool(arg1)) {
// current, target, params?, base?
return urlbuilder.buildUrl($state.current, target, undefined, arg1);
return urlbuilder.buildUrl(cs, target, undefined, arg1);
} else {
target = browser.resolve(current, toName(arg1), false);
// current, target, params?, base?
return urlbuilder.buildUrl($state.current, target, undefined, undefined);
return urlbuilder.buildUrl(cs, target, undefined, undefined);
}
}

Expand All @@ -586,10 +586,10 @@ var $StateProvider = [<any>'$routeProvider', '$stateTransitionProvider', '$pipel

if (isBool(arg2)) {
// current, target, params?, base?
return urlbuilder.buildUrl($state.current, target, undefined, arg2);
return urlbuilder.buildUrl(cs, target, undefined, arg2);
} else {
// current, target, params?, base?
return urlbuilder.buildUrl($state.current, target, arg2, arg3);
return urlbuilder.buildUrl(cs, target, arg2, arg3);
}
},
is: function (state, params) {
Expand Down Expand Up @@ -684,6 +684,7 @@ var $StateProvider = [<any>'$routeProvider', '$stateTransitionProvider', '$pipel
.then(function () {
current = changes.to;
defered.resolve(current);
currentForUrls = $state.current;
})
.catch(defered.reject);
return defered.promise.finally(function () { inProgress = false; });
Expand Down

0 comments on commit 07d1cc9

Please sign in to comment.