Last active
January 4, 2016 21:29
-
-
Save DavidBennettPIO/8681606 to your computer and use it in GitHub Desktop.
Revisions
-
DavidBennettPIO revised this gist
Jan 29, 2014 . 2 changed files with 42 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -24,7 +24,7 @@ can.routeVC = can.Construct.extend('can.routeVC', { self.constructor.data = data; $( attachTo ).html( can.view( self.constructor.view_dir+config.view+self.constructor.view_ext, self.constructor.data ) ); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,41 @@ var Todo = can.Model({ findAll : 'GET /todos', findOne : 'GET /todos/{id}', create : 'POST /todos', update : 'PATCH /todos/{id}', destroy : 'DELETE /todos/{id}' },{}) var TodosControl = can.Control.extend({ init: function() { console.log("init Todos"); }, index: function( params, render ) { can.when(Todo.findAll()).then(function(todos){ render({todos:todos}); }); }, show: function( params, render ) { can.when(Todo.findOne(params['id'])).then(function(todo){ render({todo:todo}); }); } }); new can.routeVC('#view', { "todos route": { control: TodosControl, action: 'index' }, "todos/:id route" : { control: TodosControl, action: 'show' } }); can.route.ready() -
DavidBennettPIO created this gist
Jan 29, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,73 @@ can.routeVC = can.Construct.extend('can.routeVC', { routerControl:null, view_dir: 'views/', view_ext: can.view.ext, data: {} },{ init: function(attachTo, routes){ var self = this; var route_config = {} if(routes.hasOwnProperty('init')) { route_config['init'] = routes.init; delete routes.init; } var route_render = function(config){ var render = function(data){ self.constructor.data = data; $( attachTo ).html( can.view( self.constructor.view_dir+config.action+self.constructor.view_ext, self.constructor.data ) ); } return function(params){ if(config.hasOwnProperty('action')) { var control = new config.control(); control[config.action](params, render); }else{ new config.control(params, render); } } } can.each(routes, function(config, route){ if(!config.hasOwnProperty('view')) { if(config.hasOwnProperty('action')) { config.view = config.action; }else{ config.view = 'index'; } } route_config[route] = route_render(config); }) var RouterControl = can.Control.extend(route_config); self.constructor.routerControl = new RouterControl(window); } });