Skip to content
This repository has been archived by the owner on Sep 3, 2022. It is now read-only.

Commit

Permalink
Refactored runtime so init method can be a NOOP.
Browse files Browse the repository at this point in the history
1. Normally program.init needs to return an array. But now you can make a default program with noop methods:
const program = {
  init() {},
  view() {},
  update() {}
}
  • Loading branch information
Wobbabits committed Nov 4, 2018
1 parent 86669c1 commit 8eca517
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ View is a function that can return some kind of presentation of the state. This
import { h, render, run } from '@composi/core'
// Minimal valid program to run:
const program = {
init: [],
init() {},
update() {},
view() {}
}
Expand Down
2 changes: 1 addition & 1 deletion dist/composi-core.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/composi-core.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@composi/core",
"version": "0.9.0",
"version": "0.9.1",
"description": "A JavaScript library for creating websites, PWAs and hybrid apps.",
"main": "src/index.js",
"scripts": {
Expand Down
5 changes: 4 additions & 1 deletion src/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,13 @@ export function run(program) {
* @return {void} undefined
*/
function change(update) {
let init = program.init()
if (update) {
;[state, effect] = update
} else if (init && init.length) {
;[state, effect] = init
} else {
;[state, effect] = program.init()
state = []
}
if (effect) {
effect(send)
Expand Down
2 changes: 1 addition & 1 deletion test/runtime.html
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ <h1>Mocha Tests - Composi Runtime &amp; Union</h1>
}
const program = {
init() {
return [0, effect]
return [null, effect]
},
update() {},
view() {},
Expand Down

0 comments on commit 8eca517

Please sign in to comment.