CanJS multiple page app - javascript-framework

The tutorials and example I've seen are all single page application.
Can anyone give an idea or point to a resource showing how a multiple page app can be developed with CanJS?

You should be able to create a new page in whatever app framework you are using or even just static pages, and then hookup your new control and view to any element on that new page.
You want to have a separate control for each module, so you might have separate controls even on a single page if you have, for example, a filterable dropdown list, a todo list, and a login. So, in your canjs directory for your app you will have separate sub-directories for each module which will contain your control, view/s, model/s, and observe/s and unit tests. This makes them re-usable, easier to test, and since they are modular if one part of your app breaks it won't take down all functionality. Once you get the hang of that incorporate AMD style loading of your assets with stealJS which is made by Bitovi - the CanJS creators.
https://github.com/bitovi/steal
If you want to manipulate the location.hash without actually changing pages or manaage browser history and client state you should check out can.route:
http://canjs.com/docs/can.route.html

Related

How to structure a website so that it can be extended by the user?

I am developing a website which unlike others, everything will run on end user's computer. Application will start a server then user will go to localhost to see the GUI. One part of my GUI is called a view. It represents a component which will be provided by the server as a json object.
Which component and view should be rendered will be determined by url parameters like:
localhost?component=mycomponent&view=myview
I want end users to be able to create their own views and someway register them to the application. Let's say they created a view called "userview" and registered it to the application. Now they should be able to go to:
localhost?component=mycomponent&view=userview
And see their representation of the same component.
I will most likely use spring boot for back-end (in case that matters). Views are just HTML, CSS and JS.
I have no idea how to structure such application or even if it's possible. If it is, how would one structure such application? How should the registration be handled?
Update: Solution
I dedicated a folder called "views" in which my server serves all resources under it. Users write their views as simple static websites and put files under that folder. I used an iframe element to embed these websites.
I added all the component related information to parent frame's window element like:
window.viewContext = {}
So that user's can access component related information in their views like:
parent.viewContext

Accessing objects defined in main addon script from content and page scripts in Firefox addons

I am making bootstrapped extension for Firefox (actually, trying to port working Chrome extension).
In Chrome it was:
Background page holds backgroundApp which is an instance of Marionette.Application and its modules hold Backbone models of data and do storage and sync stuff.
Popup page holds popupApp which is another instance of Marionette.Application and its modules take care of UI with views and routers defined in them. To get data, popup uses reference to backgroundApp accessed via chrome.extension.getBackgroundPage().
Now I am having a really hard time finding how I can pass models to popup panel code in Firefox, all messaging mechanisms I've encountered so far only take JSONable data.
You will have no joy if you're trying to use javascript frameworks in firefox addons. At least if you're using them beyond the scope of a single window object.
There are multiple different, fairly isolated environments in which scripts run. If we take e10s (multi-process firefox) into consideration then the addon main code will run in the parent process while anything that interacts with page content will run in the content process(es).
Message-passing is the only way to interact between those environments, and while it is possible to have remote proxies for complex objects those cause some considerable performance penalty and their usage is discouraged.
So you can have your backbone/marionette stuff run in a panel or in an invisible page (that's what the background page API does?) but if you want to have them communicate with each other you will have to get your data into some serialiazable shape.
Depending on your needs it might be sufficient if you implement copy constructors for your models. I.e. constructors which optionally take plain javascript objects (bags of values) and re-create the properly typed models from that. This requires that the objects can be fully reconstructed based on their enumerable own-properties.

How to build a paper-element app with dart?

I want to build a large application in Dart using material design. To accomplish this I included paper_elements into my project. My problem is, that I can't think of a good way to build my multi page application with paper_elements. Usually I create objects which would create their elements inline and add / remove themselves to the dom. The way I understand the paper_element tutorials I found so far this is not possible with them.
Is there a simple way to use paper_elements in dart while having an object based structure? For example I would have my application which loads either a register or login object and displays it in the browser. When logging in it should load a menu object which displays a menu and so on. All page changes should happen without a page reload.
I'm looking forward to all help, examples or links you could provide regarding my problem.
Cheers,
Tim
In Dart you normally build the app as SPA (single page application) without reload.
You can add remove a paper-element like normal DOM elements (div, input, ...) querySelector('#placeholder').append(new Element.tag('paper-input'));
You can also use <template if="{{}}"> or <template repeat="{{}}"> to make Polymer auto-insert these elements when certain conditions are fulfilled or for each value in a collection.
Your question isn't very specific but I guess all you need is already available here on SO as Q/A. Just search for [dart-polymer]. If you don't find anything just ask and we point you in the right direction.
a few that might be relevant
Dart Language: Polymer - Working with views
How to update polymer element bindings after it was removed from DOM and inserted again
How to add attributes to a dynamically created component
how to implement a main function in polymer apps (you don't need a main() when you use a polymer-element that acts as a container for your entire application)
Is imperative Mustache-Binding in Polymer.dart supported?

Having multiple AngularJS apps for one site?

I am developing a site that can be broken down to a handful of main pages. These pages can be thought as isolated from each other, except they share the session data (ie. session id and logged-in username).
Initially, I was gonna build the site as a SPA using ng-view (ie. make the pages into AngularJS views). But then, I don't see any benefits for my site to be implemented in that way. And it would require extra time and efforts to make it support SEO (Making AJAX Applications Crawlable).
Going with an approach that does not provide any benefits and even creates extra workload doesn't seem to be too smart. So I thought to myself, why don't I make the main pages of my site into individual AngularJS apps. The parts of the site that need to be indexed by search engines are simply the initial screens of some of those apps, so I wouldn't need to do extra work for SEO. (Note: The initial screens are rendered by the Django server with data for search engines to crawl, so they are non-blank.)
For each of the apps, it may or may not have its own set of partials, depending on the requirements on it.
Example:
mydomain.com/item_page/1234 (load "item" app)
mydomain.com/dashboard (load "dashboard" app)
mydomain.com/account (load "account" app and default to "tab_1" view)
mydomain.com/account#tab_1 (load "tab_1" view of "account" app)
mydomain.com/account#tab_2 (load "tab_2" view of "account" app)
mydomain.com/post_item (load "post" app)
This is solely my random thought and I haven't seen any AngularJS examples that are comprised of multiple AngularJS apps. I would like to know:
Is the multiple-AngularJS-apps for one site approach feasible? What are some caveats that I should be aware of? Are there any example site out there in the wild that's taking this approach?
If feasible, how do I share the session data between the apps?
Note this post is about multiple AngularJS apps for one site, not multiple AngularJS apps on the same page.
There is nothing wrong with such approach, as long as you keep the size of downloaded JS script small enough, and ensure good caching. One of examples of such applications can be GitHub (they are not using angular, but approach is the same). When you go Issues page on GitHub, it loads an html page, common Github JS libraries and page specific JS code. Navigation and actions inside page, are handled by that single page specific script. If you go to other section (like Code) a new page with new page specific JS code will be loaded. Another example is Amazon AWS console, they even use different frameworks for different pages. (both GitHub and Amazon don't use Angular, but this approach works for any JS based framework, even for GWT).
As for sharing some session data between pages, you can embed this info directly in the page itself, using inline scripts or hidden elements. E.g. when your server is generating page, it should also generate some session information into the page. Another approach is to download session data once, and store them in local storage/session storage.

When to use more than one Sammy.js application?

As I'm learning about Sammy.js I read that you can have several Sammy.js applications in the same page, each bound to a different element (i.e. div). I would like to understand why would this be useful.
I read in another post that only forms inside a bound element will trigger the route change, I'm thinking this could be used to modularize your application. Is there another use case beside this? Could you provide an example of how to modularize your application in this way?
We implemented a component similar to Sammy in our Silverlight application some time ago. The similarity is in that both represent a kind of a simple browser that can be bound to a UI region. The approach gave us several benefits:
We had an extensible way to add new content implementations. I mean that we could add plugins to our app that contained new forms/views which the application core had no knowledge about.
We could easily implement composite views, e.g. dashboard that were able to show any view implemented in any module. Including themselves. (A-ha, we had created recursive dashboards that worked until the app hit the memory limit. Kind of Inception. :))
Sammy can be used to reach these goals as well.
However, you must understand that from all Sammy applications running on a page, only one can be bound to the browser location bar. Others will have their location visible only to javascript, or you'll need to render location bars for them on the page.

Resources