Last active
November 25, 2020 11:41
-
-
Save ACoolmanBigHealth/0e71cc5367eaadb54d1e98f929f09e41 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const wrapper = document.createElement('div'); | |
// Available variables: | |
// - Machine | |
// - interpret | |
// - assign | |
// - send | |
// - sendParent | |
// - spawn | |
// - raise | |
// - actions | |
// - XState (all XState exports) | |
const fetchMachine = Machine({ | |
id: 'carousel', | |
initial: 'idle', | |
context: { | |
retries: 0 | |
}, | |
states: { | |
idle: { | |
on: { | |
mousedown: 'dragging' | |
} | |
}, | |
dragging: { | |
on: { | |
mouseup: 'seeking', | |
} | |
}, | |
seeking: { | |
on: { | |
arrive: 'idle', | |
mousedown: 'dragging' | |
} | |
} | |
// failure: { | |
// on: { | |
// RETRY: { | |
// target: 'loading', | |
// actions: assign({ | |
// retries: (context, event) => context.retries + 1 | |
// }) | |
// } | |
// } | |
// } | |
} | |
}); | |
const createWrapper = () => { | |
let el = document | |
.createElement('div'); | |
el | |
.setAttribute( | |
'style', | |
'display:block; idth: 100px; height: 100px; background-color: blue;' | |
); | |
el.setAttribute('id', 'car') | |
return el; | |
} | |
const createItem = num => { | |
const item = document.createElement('div'); | |
item.setAttribute( | |
'style', | |
'width: 10px; height: 10px; background-color: green;' | |
) | |
return item; | |
} | |
const carousel = document.getElementById('car') || createWrapper(); | |
carousel.innerHTML = ''; | |
const items = [1,2].map(createItem); | |
items.forEach(item => { | |
carousel.appendChild(item); | |
}) | |
document.body.appendChild(carousel) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment