Skip to content

Commit

Permalink
Adds examples for the vanilla implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
JesuHrz committed Feb 1, 2023
1 parent b985ffc commit 699a55f
Showing 1 changed file with 13 additions and 22 deletions.
35 changes: 13 additions & 22 deletions examples/vanilla/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,32 @@
<body>
<p>Count: <span class="js-count">0</span></p>
<button class="js-increment">+1</button>
<button class="js-restore-one">Restore to inital value</button>
<button class="js-restore-two">Restore from scratch</button>
<button class="js-reset">Restore to inital value</button>
<button class="js-reset-from-scratch">Restore from scratch</button>
<script src="../../dist/killa.min.js"></script>
<script>
const killa = window.killa

const $text = document.querySelector('.js-count')
const $button = document.querySelector('.js-increment')
const $restoreOne = document.querySelector('.js-restore-one')
const $restoreTwo = document.querySelector('.js-restore-two')
const $restoreOne = document.querySelector('.js-reset')
const $restoreTwo = document.querySelector('.js-reset-from-scratch')

const store = killa.createStore({
count: 0,
text: '',
user: {
name: 'Jesus Hernandez',
range: [0, 1] }
}
)
const store = killa.createStore({ count: 0, text: '' })

window.addEventListener('DOMContentLoaded', () => {
store.subscribe((state, prevState) => {
// console.log('Updated state', store.getState())
console.log('state', state)
console.log('prevState', prevState)
console.log('Updated state', store.getState())
})

// store.subscribe((state) => {
// console.log('Updated new state', state)
// $text.textContent = store.getState().count
// }, (state) => state.count)
store.subscribe((state) => {
console.log('Updated count state', state)
$text.textContent = store.getState().count
}, (state) => state.count)

// store.subscribe(() => {
// console.log('Updated text state', store.getState())
// }, (state) => state.text)
store.subscribe(() => {
console.log('Updated text state', store.getState())
}, (state) => state.text)

$button.addEventListener('click', () => {
store.setState((state) => {
Expand Down

0 comments on commit 699a55f

Please sign in to comment.