-
-
Save mbroadst/98d57788b9ce1cb681cf to your computer and use it in GitHub Desktop.
Aurelia simple grid example
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 characters
| <template> | |
| <require from="./grid/grid"></require> | |
| <require from="./grid/column"></require> | |
| <grid rows.bind="people"> | |
| <column>${$index}</column> | |
| <column>${firstName}</column> | |
| <column>${lastName}</column> | |
| </grid> | |
| </template> |
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 characters
| export class App { | |
| people = [ | |
| { firstName: 'Rob', lastName: 'Eisenberg' }, | |
| { firstName: 'Jeremy', lastName: 'Danyow' }, | |
| { firstName: 'Matt', lastName: 'Broadst' } | |
| ]; | |
| } |
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 characters
| import {inject, processContent, noView, ViewCompiler} from 'aurelia-framework'; | |
| @noView | |
| @processContent(false) | |
| @inject(Element, ViewCompiler) | |
| export class Column { | |
| constructor(element, viewCompiler, grid) { | |
| let template = `<template>${element.innerHTML}</template>`; | |
| this.viewFactory = viewCompiler.compile(template); | |
| } | |
| } |
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 characters
| <template> | |
| <content></content> | |
| </template> |
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 characters
| import { | |
| inject, bindable, children, createOverrideContext, | |
| ViewSlot, TaskQueue | |
| } from 'aurelia-framework'; | |
| @inject(ViewSlot, TaskQueue) | |
| export class Grid { | |
| @children('column') columns; | |
| @bindable rows; | |
| columnViewFactories = []; | |
| constructor(viewSlot, taskQueue) { | |
| this.viewSlot = viewSlot; | |
| this.taskQueue = taskQueue; | |
| } | |
| bind(bindingContext, overrideContext) { | |
| //this.taskQueue.queueMicroTask(() => this.render(this.bindingContext, this.overrideContext)); | |
| this.scrapeColumnsForViewFactories(); | |
| this.render(this.bindingContext, this.overrideContext); | |
| } | |
| scrapeColumnsForViewFactories() { | |
| for (let i = 0; i < this.columns.length; ++i) | |
| this.columnViewFactories.push(this.columns[i].viewFactory); | |
| } | |
| render(bindingContext, overrideContext) { | |
| let rows = this.rows; | |
| for (let y = 0, yy = rows.length; y < yy; y++) { | |
| let rowBindingContext = rows[y]; | |
| let rowOverrideContext = createOverrideContext(rowBindingContext, overrideContext); | |
| rowOverrideContext.$first = y === 0; | |
| rowOverrideContext.$last = y === yy - 1; | |
| rowOverrideContext.$index = y; | |
| // let rowView = this.rowViewFactory.create(); | |
| // this.viewSlot.add(rowView); | |
| for (let x = 0, xx = this.columnViewFactories.length; x < xx; x++) { | |
| let cellViewFactory = this.columnViewFactories[x]; | |
| let cellView = cellViewFactory.create(); | |
| cellView.bind(rowBindingContext, rowOverrideContext); | |
| //rowView.add(cellView); | |
| this.viewSlot.add(cellView); | |
| } | |
| } | |
| } | |
| } |
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 characters
| <!doctype html> | |
| <html> | |
| <head> | |
| <title>Aurelia</title> | |
| <meta name="viewport" content="width=device-width, initial-scale=1"> | |
| </head> | |
| <body aurelia-app> | |
| <h1>Loading...</h1> | |
| <script src="https://cdn.rawgit.com/jdanyow/aurelia-bundle/v1.0.4/jspm_packages/system.js"></script> | |
| <script src="https://cdn.rawgit.com/jdanyow/aurelia-bundle/v1.0.4/config.js"></script> | |
| <script> | |
| System.import('aurelia-bootstrapper'); | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment