Last active
May 28, 2020 12:35
-
-
Save xavxyz/ef96796d7f8d861ebed6b5f1fcaf89af to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains 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
// Available variables: | |
// - Machine | |
// - interpret | |
// - assign | |
// - send | |
// - sendParent | |
// - spawn | |
// - raise | |
// - actions | |
// - XState (all XState exports) | |
const nouveauParcours = { | |
cv: 'NOUVEAU FICHIER.pdf', | |
experiences: ['Joueur de pipeau', 'Chez Roger', 'Vagabondage'], | |
educations: ["L'école", 'Boucher', 'La rue'] | |
}; | |
const upload = assign({ | |
cv: () => nouveauParcours.cv | |
}); | |
// this function is created just for the art of state | |
const factory = (fn) => { | |
return ['experiences', 'educations'].reduce((newContext, key) => ({ | |
...newContext, | |
[key]: (context) => fn(key, context) | |
}), {}) | |
}; | |
const remplacer = assign(factory( | |
(key) => nouveauParcours[key] | |
)); | |
const conserver = assign(factory( | |
(key, context) => context[key].concat(nouveauParcours[key]) | |
)); | |
const fetchMachine = Machine({ | |
id: 'parcours-freelance', | |
initial: 'en-attente', | |
context: { | |
cv: 'FICHIER.PDF', | |
experiences: ['Chez Roger', 'Chez Jean-Louis'], | |
educations: ['Boucher', 'Pharmacien'] | |
}, | |
states: { | |
'en-attente': { | |
on: { | |
AJOUT_DU_CV: 'importation' | |
} | |
}, | |
importation: { | |
on: { | |
SUCCES: { | |
target: 'choix-du-parcours', | |
actions: upload | |
}, | |
ERREUR: 'echec-d-importation', | |
PAGE_FERMEE: { | |
target: 'plus-rien-à-faire', | |
actions: [upload, remplacer] | |
} | |
} | |
}, | |
'choix-du-parcours': { | |
on: { | |
CONSERVER: { | |
target: 'plus-rien-à-faire', | |
actions: conserver | |
}, | |
REMPLACER: { | |
target: 'plus-rien-à-faire', | |
actions: remplacer | |
}, | |
PAGE_FERMEE: { | |
target: 'plus-rien-à-faire', | |
actions: remplacer | |
} | |
} | |
}, | |
'echec-d-importation': { | |
on: { | |
RETRY: 'en-attente', | |
} | |
}, | |
'plus-rien-à-faire': { | |
type: 'final' | |
}, | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment