Skip to content

Commit

Permalink
Adding data to the model
Browse files Browse the repository at this point in the history
  • Loading branch information
benburton committed Jan 30, 2017
1 parent d26f76a commit b7a2053
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 2 deletions.
11 changes: 11 additions & 0 deletions controller/package.json
@@ -0,0 +1,11 @@
{
"name": "pie-toggle-controller",
"version": "1.0.0",
"description": "",
"main": "src/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
15 changes: 15 additions & 0 deletions controller/src/index.js
@@ -0,0 +1,15 @@
export function outcome(question, session) {

return new Promise((resolve) => {
resolve({});
});

}

export function model(question, session, env) {

return new Promise((resolve) => {
resolve(question);
});

}
3 changes: 2 additions & 1 deletion docs/demo/config.json
Expand Up @@ -5,7 +5,8 @@
"models": [
{
"id": "1",
"element": "pie-toggle"
"element": "pie-toggle",
"message": "hello, PIE"
}
]
}
31 changes: 30 additions & 1 deletion src/index.js
Expand Up @@ -2,11 +2,40 @@ export default class Toggle extends HTMLElement {

constructor() {
super();
this._model = null;
this._session = null;
this._rerender();
}

set model(m) {
this._model = m;
this._rerender();
}

set session(s) {
this._session = s;
this._rerender();
}

get session() {
return this._session;
}

_message() {
return this._model ? this._model.message : 'hello, world';
}

_rerender() {
this.innerHTML = [
'<div>',
"hello, world",
this._message(),
'</div>'
].join('\n');
}

connectedCallback() {
this.dispatchEvent(new CustomEvent('pie.register', { bubbles: true }));
this._rerender();
}

}

0 comments on commit b7a2053

Please sign in to comment.