This is a playground
to test code. It runs a full Node.js
environment and already has all of npm
’s 1,000,000+ packages pre-installed, including vuex-observable-plugin
with all npm
packages installed. Try it out:
// Imports dependencies.
const Vue = require('vue')
const Vuex = require('vuex')
const { VuexObservable, ofType } = require('vuex-observable-plugin')
const { map } = require('rxjs/operators')
// Defines a simple epic.
const epics = [
(action$, store$, { ofType, map }) => {
return action$.pipe(
ofType('GENERATE_RANDOM_NUMBER'),
map(() => ({ type: 'SET_NUMBER', payload: Math.random() }))
)
}
]
// Defines state.
const state = {
number: 0
}
// Defines mutation.
const mutations = {
SET_NUMBER (state, number) {
state.number = number
}
}
// Initialises the store.
Vue.use(Vuex)
const store = new Vuex.Store({
state,
mutations,
plugins: [VuexObservable(epics, { dependencies: { ofType, map } })]
})
// Dispatches an epic.
store.dispatch('GENERATE_RANDOM_NUMBER')
// Loggs the state after the epic has run.
console.log(store.state.number)
This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.