Last active
March 24, 2020 06:29
-
-
Save tarasowski/6b2057a602e3e4f8efef2a71bd0a8e71 to your computer and use it in GitHub Desktop.
How to deal w/ side-effects
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
import { objectivesStore, keyResultsStore, listOKRs, deleteOKR as deleteOKRMutation, updateOKR } from './stores/okrs.js' | |
import { teamStore, listTeams } from './stores/teams.js' | |
import { error } from './stores/errors.js' | |
import { memberStore, listMembers } from './stores/members.js' | |
import { fork, reject, parallel } from 'fluture' | |
import { onMount } from 'svelte' | |
import { pipe, head, filter, maybe, map, prop, sortBy } from './sanctuary.js' | |
let viewMode | |
export const listOKRs = | |
encaseP(query => API.graphql(graphqlOperation(query))) (listOKRsQuery) | |
.pipe (map (prop ('data'))) | |
.pipe (map (prop ('listOKRs'))) | |
.pipe (map (sortBy (prop ('timeAdded')))) | |
export const listMembers = | |
encaseP(query => API.graphql(graphqlOperation(query))) (listMembersQuery) | |
.pipe (map (prop ('data'))) | |
.pipe (map (prop ('listMembers'))) | |
export const listTeams = | |
encaseP(query => API.graphql(graphqlOperation(query))) (listTeamsQuery) | |
.pipe (map (prop ('data'))) | |
.pipe (map (prop ('listTeams'))) | |
const basicError = () => error.set('Something went wrong. Please try again') | |
const initState = ([okrs, teams, members]) => | |
objectivesStore.set(okrs) | |
|| teamStore.set(teams) | |
|| memberStore.set(members) | |
onMount(() => | |
parallel (3) ([listOKRs, listTeams, listMembers]) | |
.pipe (map (initState)) | |
.pipe (fork (basicError) (() => viewMode = 'main'))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment