Import/export works!
This commit is contained in:
parent
78e4f0ecd8
commit
202d77e0cc
2 changed files with 79 additions and 40 deletions
|
|
@ -28,6 +28,7 @@ export const newExporter = ({
|
|||
|
||||
export const newImporter = ({
|
||||
accept = '.json',
|
||||
parser = (string) => JSON.parse(string),
|
||||
onImport,
|
||||
onImportFailure,
|
||||
validator = () => true
|
||||
|
|
@ -44,7 +45,7 @@ export const newImporter = ({
|
|||
const reader = new FileReader()
|
||||
reader.onload = ({ target }) => {
|
||||
try {
|
||||
const parsed = JSON.parse(target.result)
|
||||
const parsed = parser(target.result)
|
||||
const validationResult = validator(parsed, filename)
|
||||
if (validationResult === true) {
|
||||
onImport(parsed, filename)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue