Last active
December 27, 2017 10:02
-
-
Save jdanyow/7394bd712b8ba078dedd to your computer and use it in GitHub Desktop.
Aurelia simple grid example
This file contains 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/cell-template"></require> | |
<require from="./grid/row-template"></require> | |
<grid items.bind="people"> | |
<row-template> | |
<div> | |
<content></content> | |
</div> | |
</row-template> | |
<cell-template>${$index}</cell-template> | |
<cell-template>${firstName}</cell-template> | |
<cell-template>${lastName}</cell-template> | |
</grid> | |
</template> |
This file contains 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 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'; | |
import {Grid} from './grid'; | |
@inject(Element, ViewCompiler, Grid) | |
@processContent(false) | |
@noView | |
export class CellTemplate { | |
constructor(element, viewCompiler, grid) { | |
let template = `<template>${element.innerHTML}</template>`; | |
let viewFactory = viewCompiler.compile(template); | |
grid.cellViewFactories.push(viewFactory); | |
} | |
} |
This file contains 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 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, | |
ViewSlot, | |
processContent, | |
noView, | |
containerless, | |
bindable, | |
createOverrideContext, | |
TaskQueue | |
} from 'aurelia-framework'; | |
@inject(ViewSlot, TaskQueue) | |
export class Grid { | |
@bindable items; | |
cellViewFactories = []; | |
rowViewFactory = null; | |
constructor(viewSlot, taskQueue) { | |
this.viewSlot = viewSlot; | |
this.taskQueue = taskQueue; | |
} | |
bind(bindingContext, overrideContext) { | |
//this.taskQueue.queueMicroTask(() => this.render(this.bindingContext, this.overrideContext)); | |
this.render(this.bindingContext, this.overrideContext); | |
} | |
render(bindingContext, overrideContext) { | |
debugger; | |
let items = this.items; | |
for (let y = 0, yy = items.length; y < yy; y++) { | |
let rowBindingContext = items[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.cellViewFactories.length; x < xx; x++) { | |
let cellViewFactory = this.cellViewFactories[x]; | |
let cellView = cellViewFactory.create(); | |
cellView.bind(rowBindingContext, rowOverrideContext); | |
//rowView.add(cellView); | |
} | |
} | |
} | |
} |
This file contains 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'; | |
import {Grid} from './grid'; | |
@inject(Element, ViewCompiler, Grid) | |
@processContent(false) | |
@noView | |
export class RowTemplate { | |
constructor(element, viewCompiler, grid) { | |
let template = `<template>${element.innerHTML}</template>`; | |
let viewFactory = viewCompiler.compile(template); | |
grid.rowViewFactory = viewFactory; | |
} | |
} |
This file contains 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.3/jspm_packages/system.js"></script> | |
<script src="https://cdn.rawgit.com/jdanyow/aurelia-bundle/v1.0.3/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