Single Page Interface

381 views
Skip to first unread message

Ω Alisson

unread,
Apr 25, 2011, 2:52:24 PM4/25/11
to knock...@googlegroups.com
Now that KnockoutJS 1.2 arrived, I can see an easy implementation of Single Page Interface with Knockout External Template Engine, Knockout namespaces and templateOptions. Does anyone tried stuff like this?

Ω Alisson

unread,
Apr 25, 2011, 4:51:34 PM4/25/11
to knock...@googlegroups.com
With a bit of convention, actually it works pretty good, see my proof-of-concept here:

Jacob Atzen

unread,
Apr 25, 2011, 4:54:47 PM4/25/11
to knock...@googlegroups.com
I think maybe something's missing from the repository. I'm getting "The template could not be loaded. HTTP Status code: 0." when I open index.html in my browser.

--
Cheers,
- Jacob Atzen

Ω Alisson

unread,
Apr 25, 2011, 5:02:30 PM4/25/11
to knock...@googlegroups.com
Strange, I've tested it with some friends and it is working :(

Jacob Atzen

unread,
Apr 25, 2011, 5:07:31 PM4/25/11
to knock...@googlegroups.com
Works in Safari, not in Chrome for some reason.

--
Cheers,
- Jacob Atzen

Herb Caudill

unread,
Apr 25, 2011, 5:18:06 PM4/25/11
to KnockoutJS
I got that message when just opening the HTML file in Chrome (from
Windows) but not when serving it from a web server (in my case the
built-in Visual Studio server).

On Apr 25, 4:54 pm, Jacob Atzen <jat...@gmail.com> wrote:
> I think maybe something's missing from the repository. I'm getting "The template could not be loaded. HTTP Status code: 0." when I open index.html in my browser.
>
> --
> Cheers,
> - Jacob Atzen
>
>
>
>
>
>
>
> On Monday, April 25, 2011 at 22:51 , Ω Alisson wrote:
> > With a bit of convention, actually it works pretty good, see my proof-of-concept here:
>
> >https://github.com/thelinuxlich/knockout.spi
>
> > 2011/4/25 Ω Alisson <thelinuxl...@gmail.com>

Jacob Atzen

unread,
Apr 25, 2011, 5:22:02 PM4/25/11
to knock...@googlegroups.com
That does the trick. Thanks!

--
Cheers,
- Jacob Atzen

Guillaume

unread,
Apr 25, 2011, 5:31:14 PM4/25/11
to KnockoutJS
chrome security policy forbid local XHR -_-
http://code.google.com/p/chromium/issues/detail?id=47416

Ω Alisson

unread,
Apr 25, 2011, 6:10:06 PM4/25/11
to knock...@googlegroups.com
Oh, I forgot this issue, thanks Guillaume!

Ω Alisson

unread,
Apr 25, 2011, 7:10:28 PM4/25/11
to knock...@googlegroups.com
Updated the project with jquery.address integration

2011/4/25 Ω Alisson <thelin...@gmail.com>

Jacob Atzen

unread,
Apr 26, 2011, 3:46:34 AM4/26/11
to knock...@googlegroups.com
Sweet. I'd be curious to see how you would implement showing the relevant section based on the URL too. As in when I paste /#/cars%3Aindex into the browser.

--
Cheers,
- Jacob Atzen

Ω Alisson

unread,
Apr 26, 2011, 9:44:47 AM4/26/11
to knock...@googlegroups.com
I've simplified the project a LOT now, but noticed some weird behavior:

- Template is called many times on the same function
- I need to use setTimeout for applyBindings in a nested template(see the list of users on Users section), why?

Ω Alisson

unread,
Apr 26, 2011, 10:52:35 AM4/26/11
to knock...@googlegroups.com
Solved the template calling many times, was a jquery address misusing, now the only thing that bugs me is why I need to use setTimeout to applyBindings on template

2011/4/26 Ω Alisson <thelin...@gmail.com>

Joel Dart

unread,
Apr 26, 2011, 10:04:11 PM4/26/11
to KnockoutJS
Thanks for the project, Alisson. This is an area that needs a lot of
work/discussion, so I'm glad you're pushing it ahead.

The reason you have to call setTimeout in the nested template is
because the template script is being run before the template has been
inserted in the dom. use a .debug version of knockout.namespaces.js
and step through the ko.applyBindings method in firebug (since
namespace duckpunches applyBindings, you'll have to set the breakpoint
in the ko.namespace file). The results of
ko.utils.getElementsHavingAttribute is the old dom element if you
don't use the timeout. I'm still tracking down where the script is
actually getting evaluated/inserted, so I don't have the complete
picture, but I thought I'd report on the small piece of the puzzle I
have to offer.

Ω Alisson

unread,
Apr 26, 2011, 10:07:15 PM4/26/11
to knock...@googlegroups.com
Thanks a lot for the protip, Joel! Calling setTimeout looks unsafe so I don't know if I'm going the right road

Ω Alisson

unread,
Apr 27, 2011, 11:20:53 AM4/27/11
to knock...@googlegroups.com
Man, such a pain this integration of jquery address + knockout :(

2011/4/26 Ω Alisson <thelin...@gmail.com>

Felipe Leusin

unread,
Apr 27, 2011, 11:41:08 AM4/27/11
to knock...@googlegroups.com
Have you considered using sammy just for the "routing" part?

Ω Alisson

unread,
Apr 27, 2011, 11:43:59 AM4/27/11
to knock...@googlegroups.com
How could I use Sammy in a dynamic way? From what I saw on its project page, it looks like I need to bootstrap it with fixed routes

Ω Alisson

unread,
Apr 27, 2011, 2:38:05 PM4/27/11
to knock...@googlegroups.com
Ok, now I think jquery.address is behaving nicely with this experiment. Please share your thoughts about it:

Ω Alisson

unread,
May 3, 2011, 4:29:18 PM5/3/11
to knock...@googlegroups.com
Now compatible with Google AJAX Crawling(#!)

Does someone here ever tried to deploy an GAE app with HTMLUnit that would automatically serve HTML snapshots for SPI applications? That would be really nice!

2011/4/27 Ω Alisson <thelin...@gmail.com>

Felipe Leusin

unread,
May 6, 2011, 12:46:09 AM5/6/11
to knock...@googlegroups.com
Not really, but just took a deeper look at you application and it's sweet.

Gonna borrow some techiniques if I ever do a SinglePage Application in the near future.

Grats

tob...@gmail.com

unread,
May 30, 2011, 5:08:44 AM5/30/11
to knock...@googlegroups.com
wanted to let you know I kind of re-worked (stole) your sample by combining a lot of bits from the external plugin to refactor that plugin out - essentially, I'm just using async and not overwriting any of the ko functions.  It's pretty messy, but I just wanted a quick poc for a larger project. 
 
Reply all
Reply to author
Forward
0 new messages