Skip to content

Instantly share code, notes, and snippets.

@ksnabb
Created December 16, 2018 12:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ksnabb/8122a3143279dfb10f57069c5ee3c540 to your computer and use it in GitHub Desktop.
Save ksnabb/8122a3143279dfb10f57069c5ee3c540 to your computer and use it in GitHub Desktop.
Seconds elapsed using pubsub.js and state.js
const appEvents = pubSub();
const appState = state(0, appEvents);
function timer() {
appState.setValue(appState.getValue() + 1);
setTimeout(timer, 1000);
}
setTimeout(timer, 1000);
function updateTimerView(val) {
document.querySelector(".seconds-elapsed").innerText = `seconds elapsed ${val}`;
}
appEvents.subscribe(updateTimerView);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment