Skip to content
Browse files

Access params in enter/exit

* calling apply on a function allows you to pass in the context for `this` which means we can pass in the route into the callback.

[fixes #23]
  • Loading branch information...
1 parent b3260dc commit 31e64648d3ec555d8d34647d2b10da6b3cf26d3d @rmontgomery429 rmontgomery429 committed Apr 27, 2012
Showing with 7 additions and 7 deletions.
  1. +1 −1 path.js
  2. +6 −6 tests/path.js.test.html
View
2 path.js
@@ -177,7 +177,7 @@ Path.core.route.prototype = {
if (Path.routes.defined[this.path].hasOwnProperty("do_enter")) {
if (Path.routes.defined[this.path].do_enter.length > 0) {
for (i = 0; i < Path.routes.defined[this.path].do_enter.length; i++) {
- result = Path.routes.defined[this.path].do_enter[i]();
+ result = Path.routes.defined[this.path].do_enter[i].apply(this, null);
if (result === false) {
halt_execution = true;
break;
View
12 tests/path.js.test.html
@@ -82,15 +82,15 @@
});
Path.map("#E/params/:id/parse").enter(function(){
- update("E[enter](parse)");
+ update("E[enter](parse id=" + this.params['id'] + ")");
});
Path.map("#E/params/:id/check").to(function(){
update("E[action](check id=" + this.params['id'] + ")");
});
Path.map("#E/params/:id/check").exit(function(){
- update("E[exit](check)");
+ update("E[exit](check id=" + this.params['id'] + ")");
});
Path.map("#F").enter(function(){
@@ -161,12 +161,12 @@
<tr><td>C[exit]</td> <td>Exit method of C, as we move to next route</td></tr>
<tr><td>RESCUE</td> <td>Rescue a route that wasn't found (D1)</td></tr>
<tr><td>RESCUE</td> <td>Rescue a route that wasn't found (D2)</td></tr>
- <tr><td>E[enter](parse)</td> <td>Enter method of a param parsed route</td></tr>
+ <tr><td>E[enter](parse id=1)</td> <td>Enter method of a param parsed route</td></tr>
<tr><td>E[action](parse id=1)</td> <td>True action of the route, with param of id=1</td></tr>
- <tr><td>E[enter](parse)</td> <td>Enter method of the same route again</td></tr>
+ <tr><td>E[enter](parse id=2)</td> <td>Enter method of the same route again</td></tr>
<tr><td>E[action](parse id=2)</td> <td>True action of the route, with param of id=2</td></tr>
<tr><td>E[action](check id=3)</td> <td>True action of the next route, with param id=3</td></tr>
- <tr><td>E[exit](check)</td> <td>Exit method of parameterized route</td></tr>
+ <tr><td>E[exit](check id=3)</td> <td>Exit method of parameterized route</td></tr>
<tr><td>F[enter]</td> <td>Enter method of F again, our final route</td></tr>
<tr><td>F[action]</td> <td>True action of F, our final route</td></tr>
<tr><td>G[enter 1]</td> <td>First enter method of G</td></tr>
@@ -181,7 +181,7 @@
</div><br /><br />
<div id="console">
<h3>Expected</h3>
- <div id="expected">F[enter]::F[action]::A[enter]::A[action]::A[exit]::B[enter]::B[action]::C[action]::C[exit]::RESCUE::RESCUE::E[enter](parse)::E[action](parse id=1)::E[enter](parse)::E[action](parse id=2)::E[action](check id=3)::E[exit](check)::F[enter]::F[action]::G[enter 1]::G[enter 2]::G[enter 3]::G[enter 4]::H(one=N/A, two=N/A)::H(one=10, two=N/A)::H(one=10, two=20)::H(one=10, two=N/A)</div>
+ <div id="expected">F[enter]::F[action]::A[enter]::A[action]::A[exit]::B[enter]::B[action]::C[action]::C[exit]::RESCUE::RESCUE::E[enter](parse id=1)::E[action](parse id=1)::E[enter](parse id=2)::E[action](parse id=2)::E[action](check id=3)::E[exit](check id=3)::F[enter]::F[action]::G[enter 1]::G[enter 2]::G[enter 3]::G[enter 4]::H(one=N/A, two=N/A)::H(one=10, two=N/A)::H(one=10, two=20)::H(one=10, two=N/A)</div>
<h3>Actual</h3>
<div id="actual"></div>
<h3>Grade</h3>

0 comments on commit 31e6464

Please sign in to comment.
Something went wrong with that request. Please try again.