Skip to content

Commit

Permalink
Adding custom template rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
eavichay committed Dec 8, 2016
1 parent a1e53f6 commit 6aac79a
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 24 deletions.
28 changes: 18 additions & 10 deletions SlimElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,16 @@
onBeforeCreated() {}
onCreated() {}
beforeRender() {}
render() {}
render(template) {
this.isForcedRender = true;
let newTemplate = template;
if (this.template !== newTemplate) {
this.__bindings = {}
this.__bindingTree = document.createElement('slim-component')
this._bindingCycle(newTemplate)
this._renderCycle()
}
}
afterRender() {}
onAdded() {}
update(root = false) {
Expand Down Expand Up @@ -222,19 +231,18 @@
this._renderCycle()
}

_bindingCycle() {
this._captureBindings()
this._applyBindings()
_bindingCycle(forcedTemplate) {
this._captureBindings(forcedTemplate)
this._applyBindings(forcedTemplate)
}

_renderCycle(skipTree = false) {
this.beforeRender()
if (!this.isForcedRender) this.beforeRender()

if (!skipTree) this.appendChild(this.__bindingTree)

this.render()
this._applyTextBindings()
this.afterRender()
if (!this.isForcedRender) this.afterRender()
this.isForcedRender = false;
}

_applyTextBindings() {
Expand Down Expand Up @@ -315,8 +323,8 @@
* private
*/

_captureBindings() {
let $tpl = this.template;
_captureBindings(forcedTemplate) {
let $tpl = forcedTemplate || this.template;
if (!$tpl) {
while (this.children.length) {
this.__bindingTree.appendChild( this.children[0] )
Expand Down
2 changes: 2 additions & 0 deletions example/Kanban/KanbanDemo.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<head>
<meta charset="UTF-8">
<title>Kanban Demo - SlimJS</title>
<link href="https://fonts.googleapis.com/css?family=Catamaran:200|Catamaran:800|Ubuntu|Ubuntu:800" rel="stylesheet" async>

<script src="../../SlimElement.js"></script>
<script src="KanbanModel.js"></script>
Expand All @@ -19,6 +20,7 @@
<style type="text/css">

body, html {
font-family: "Ubuntu", "Helvetica", Sans-serif;
width: 100%;
height: 100%;
margin: 0;
Expand Down
5 changes: 5 additions & 0 deletions example/Kanban/KanbanModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
this.tasks = []
}

getIdForNewTask() {
return this.tasks.length + 1;
}

getTasks(column) {
return this.tasks.filter( task => {
return task.column === column
Expand All @@ -19,6 +23,7 @@
addTask(title = 'New Task', description = '') {
let newTask = { title, description}
newTask.column = 'Todo'
newTask.id = this.getIdForNewTask()
this.tasks.push(newTask)
}

Expand Down
1 change: 1 addition & 0 deletions example/Kanban/kanban-app.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@
align-items: flex-start;
justify-content: space-between;
width: 100%;
height: 100%;
}
</style>
6 changes: 1 addition & 5 deletions example/Kanban/kanban-column.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@
return `<span bind>[[data.name]]</span><kanban-item slim-repeat="myTasks"></kanban-item>`
}

onAdded() {
console.log(this.myTasks)
}

get myTasks() {
return this.model.getTasks(this.data.name)
}
Expand All @@ -35,6 +31,6 @@
padding: 1em;
background: antiquewhite;
align-items: center;
justify-content: center;
justify-content: flex-start;
}
</style>
15 changes: 6 additions & 9 deletions example/Kanban/kanban-item.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

Slim('kanban-item', class extends SlimBaseElement {



get template() {
return `
<div>
Expand All @@ -15,16 +13,10 @@
</div>`
}






})




})()


Expand All @@ -41,14 +33,19 @@
justify-content: center;
}

kanban-item:last-child {
margin-bottom: 0;
}

kanban-item div {
width: 100%;
}

kanban-item .title {
font-family: "Catamaran", Sans-serif;
font-weight: normal;
display: block;
font-size: 1.3em;
width: 100%;
text-align: center;
}
</style>

0 comments on commit 6aac79a

Please sign in to comment.