diff --git a/SlimElement.js b/SlimElement.js index 3bf6a10..0e0612e 100644 --- a/SlimElement.js +++ b/SlimElement.js @@ -1,7 +1,7 @@ ;(function() { - var css = 'slim-component, s-repeat { all: inherit; padding: 0; margin: 0; background: none; }', + var css = 'slim-component, s-repeat { all: inherit; padding: 0; margin: 0; background: none; left: 0; top: 0;}', head = document.head || document.getElementsByTagName('head')[0], style = document.createElement('style'); @@ -195,14 +195,14 @@ } afterRender() {} onAdded() {} - update(root = false) { + update(root = false, flat = true) { if (root) { document.querySelectorAll('[root]').forEach( (element) => { element.update(false) }) return } - this._applyTextBindings() + if (!flat) this._applyTextBindings() for (let child of this.children) { try { child.update() @@ -210,6 +210,9 @@ catch (err) {} } } + refresh() { + this.createdCallback(true) + } onRemoved() {} //noinspection JSUnusedGlobalSymbols diff --git a/example/Kanban/KanbanDemo.html b/example/Kanban/KanbanDemo.html index 4c238ba..55930db 100644 --- a/example/Kanban/KanbanDemo.html +++ b/example/Kanban/KanbanDemo.html @@ -4,11 +4,11 @@ Kanban Demo - SlimJS + + - - diff --git a/example/Kanban/KanbanModel.js b/example/Kanban/KanbanModel.js index cbc36d2..e9744ca 100644 --- a/example/Kanban/KanbanModel.js +++ b/example/Kanban/KanbanModel.js @@ -1,15 +1,27 @@ +(function(){ "use strict"; + class Dispatcher { + constructor() { + var delegate = document.createDocumentFragment(); + ['addEventListener', 'dispatchEvent', 'removeEventListener'].forEach( + f => this[f] = (...xs) => delegate[f](...xs) + ) + } + } - - class KanbanModel { + class KanbanModel extends Dispatcher{ constructor() { + super() this.columns = [{name: 'Todo'},{name:'In-Progress'},{name:'Done'}] this.tasks = [] } + notify() { + this.dispatchEvent(new Event('change')) + } + getIdForNewTask() { return this.tasks.length + 1; } @@ -27,6 +39,11 @@ this.tasks.push(newTask) } + moveTask(task, column) { + task.column = column.name + this.notify() + } + get hello() { return 'Hello' } diff --git a/example/Kanban/kanban-app.html b/example/Kanban/kanban-app.html index c138267..4a7e27d 100644 --- a/example/Kanban/kanban-app.html +++ b/example/Kanban/kanban-app.html @@ -11,6 +11,10 @@ return this.model.columns } + afterRender() { + + } + }) diff --git a/example/Kanban/kanban-column.html b/example/Kanban/kanban-column.html index b5740b0..832853c 100644 --- a/example/Kanban/kanban-column.html +++ b/example/Kanban/kanban-column.html @@ -13,6 +13,18 @@ return this.model.getTasks(this.data.name) } + afterRender() { + this.model.addEventListener('change', () => { + this.update() + }) + $(this).droppable({ + accept: 'kanban-item', + drop: function(event, ui) { + this.model.moveTask(ui.draggable[0].data, this.data) + } + }) + } + }) diff --git a/example/Kanban/kanban-item.html b/example/Kanban/kanban-item.html index f56a4bb..f21e859 100644 --- a/example/Kanban/kanban-item.html +++ b/example/Kanban/kanban-item.html @@ -13,6 +13,14 @@ ` } + afterRender() { + $(this).draggable({ + revert: 'invalid', + revertDuration: 100, + connectWith: 'kanban-column' + }) + } + })