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

Nested 'then' not working properly. Fixed #197

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jah0wl
Copy link

@jah0wl jah0wl commented Jun 7, 2013

In previous version nested then didn't work at expected:

context.load("templates/home.template"
            ).then(function(){
                context.log("1");
                this.load("templates/home.template"
                ).then(function(){
                    context.log("2");
                    this.load("templates/home.template"
                    ).then(function(){
                        context.log("3");
                        this.load("templates/home.template"
                        ).then(function(){
                            context.log("3a");
                        }).then(function(){
                            context.log("3b");
                        });
                    });
                }).then(function(){
                    context.log("4");
                });
            }).then(function(){
                context.log("5");
            }).then(function(){
                context.log("6");
                this.load("templates/home.template"
                ).then(function(){
                    context.log("7");
                    this.load("templates/home.template"
                    ).then(function(){
                        context.log("8");
                    });
                }).then(function(){
                    context.log("9");
                });             
            });

returns:

[Fri Jun 07 2013 16:47:28 GMT+0200 (CEST)] 1 sammy.js:97
[Fri Jun 07 2013 16:47:28 GMT+0200 (CEST)] 5 sammy.js:97
[Fri Jun 07 2013 16:47:28 GMT+0200 (CEST)] 6 sammy.js:97
[Fri Jun 07 2013 16:47:28 GMT+0200 (CEST)] 2 sammy.js:97
[Fri Jun 07 2013 16:47:28 GMT+0200 (CEST)] 4 sammy.js:97
[Fri Jun 07 2013 16:47:28 GMT+0200 (CEST)] 7 sammy.js:97
[Fri Jun 07 2013 16:47:28 GMT+0200 (CEST)] 9 sammy.js:97
[Fri Jun 07 2013 16:47:39 GMT+0200 (CEST)] 3 sammy.js:97
[Fri Jun 07 2013 16:47:39 GMT+0200 (CEST)] 8 sammy.js:97
[Fri Jun 07 2013 16:47:39 GMT+0200 (CEST)] 3a sammy.js:97
[Fri Jun 07 2013 16:47:39 GMT+0200 (CEST)] 3b sammy.js:97

With the change it outputs what we expect:

[Fri Jun 07 2013 16:48:41 GMT+0200 (CEST)] 1 sammy.js:97
[Fri Jun 07 2013 16:48:41 GMT+0200 (CEST)] 2 sammy.js:97
[Fri Jun 07 2013 16:48:41 GMT+0200 (CEST)] 3 sammy.js:97
[Fri Jun 07 2013 16:48:41 GMT+0200 (CEST)] 3a sammy.js:97
[Fri Jun 07 2013 16:48:41 GMT+0200 (CEST)] 3b sammy.js:97
[Fri Jun 07 2013 16:48:41 GMT+0200 (CEST)] 4 sammy.js:97
[Fri Jun 07 2013 16:48:41 GMT+0200 (CEST)] 5 sammy.js:97
[Fri Jun 07 2013 16:48:41 GMT+0200 (CEST)] 6 sammy.js:97
[Fri Jun 07 2013 16:48:41 GMT+0200 (CEST)] 7 sammy.js:97
[Fri Jun 07 2013 16:48:41 GMT+0200 (CEST)] 8 sammy.js:97
[Fri Jun 07 2013 16:48:41 GMT+0200 (CEST)] 9 sammy.js:97

In previous version nested then didn't work at expected:

context.load("templates/home.template"
			).then(function(){
				context.log("1");
				this.load("templates/home.template"
				).then(function(){
					context.log("2");
					this.load("templates/home.template"
					).then(function(){
						context.log("3");
						this.load("templates/home.template"
						).then(function(){
							context.log("3a");
						}).then(function(){
							context.log("3b");
						});
					});
				}).then(function(){
					context.log("4");
				});
			}).then(function(){
				context.log("5");
			}).then(function(){
				context.log("6");
				this.load("templates/home.template"
				).then(function(){
					context.log("7");
					this.load("templates/home.template"
					).then(function(){
						context.log("8");
					});
				}).then(function(){
					context.log("9");
				});				
			});

returns: 

[Fri Jun 07 2013 16:47:28 GMT+0200 (CEST)] 1 sammy.js:97
[Fri Jun 07 2013 16:47:28 GMT+0200 (CEST)] 5 sammy.js:97
[Fri Jun 07 2013 16:47:28 GMT+0200 (CEST)] 6 sammy.js:97
[Fri Jun 07 2013 16:47:28 GMT+0200 (CEST)] 2 sammy.js:97
[Fri Jun 07 2013 16:47:28 GMT+0200 (CEST)] 4 sammy.js:97
[Fri Jun 07 2013 16:47:28 GMT+0200 (CEST)] 7 sammy.js:97
[Fri Jun 07 2013 16:47:28 GMT+0200 (CEST)] 9 sammy.js:97
[Fri Jun 07 2013 16:47:39 GMT+0200 (CEST)] 3 sammy.js:97
[Fri Jun 07 2013 16:47:39 GMT+0200 (CEST)] 8 sammy.js:97
[Fri Jun 07 2013 16:47:39 GMT+0200 (CEST)] 3a sammy.js:97
[Fri Jun 07 2013 16:47:39 GMT+0200 (CEST)] 3b sammy.js:97

With the change it outputs what we expect:

[Fri Jun 07 2013 16:48:41 GMT+0200 (CEST)] 1 sammy.js:97
[Fri Jun 07 2013 16:48:41 GMT+0200 (CEST)] 2 sammy.js:97
[Fri Jun 07 2013 16:48:41 GMT+0200 (CEST)] 3 sammy.js:97
[Fri Jun 07 2013 16:48:41 GMT+0200 (CEST)] 3a sammy.js:97
[Fri Jun 07 2013 16:48:41 GMT+0200 (CEST)] 3b sammy.js:97
[Fri Jun 07 2013 16:48:41 GMT+0200 (CEST)] 4 sammy.js:97
[Fri Jun 07 2013 16:48:41 GMT+0200 (CEST)] 5 sammy.js:97
[Fri Jun 07 2013 16:48:41 GMT+0200 (CEST)] 6 sammy.js:97
[Fri Jun 07 2013 16:48:41 GMT+0200 (CEST)] 7 sammy.js:97
[Fri Jun 07 2013 16:48:41 GMT+0200 (CEST)] 8 sammy.js:97
[Fri Jun 07 2013 16:48:41 GMT+0200 (CEST)] 9 sammy.js:97
@@ -1551,9 +1551,11 @@ $.extend(Sammy.DefaultLocationProxy.prototype , {
}
var context = this;
if (this.waiting) {
this.callbacks.push(callback);
this.callbacks.splice(this.inAThen,0,callback);
this.inAThen++;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we translate the push() to an splice() at the highest index inside this nested then

@endor
Copy link
Collaborator

endor commented Feb 1, 2014

Can you please add a test for this?

@jah0wl
Copy link
Author

jah0wl commented Feb 1, 2014

How do i do it?

@endor
Copy link
Collaborator

endor commented Feb 1, 2014

Look at the other tests. You might push different strings on to an array in the nested thens and then check afterwards that the strings are in the correct order. If the test fails before the change and works after, it's most likely correct (: Probably somewhere in render_context_spec.js. To run the tests, just run ruby test/test_server.

@jah0wl
Copy link
Author

jah0wl commented Feb 2, 2014

As I posted, I made a test and also send a patch to fix it... I don't really understand what you need.

@s7726
Copy link

s7726 commented May 26, 2018

@jah0wl I think he's looking for a code test, essentially what you have written out but in the spec file so that it runs as part of the automated build process.

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.

3 participants