Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 30 additions & 8 deletions src/serialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,40 @@ function replaceRecord(rec, replaceChild) {
return { "__record": rec._name, "data": recordData }
}

function getIterableType(iterable) {
switch (iterable.constructor) {
case immutable.List:
return 'List'

case immutable.Set:
return 'Set'

case immutable.OrderedSet:
return 'OrderedSet'

case immutable.Stack:
return 'Stack'

case immutable.Map:
return 'Map'

case immutable.OrderedMap:
return 'OrderedMap'

default:
return undefined
}
}


function replaceIterable(iter, replaceChild) {
debug('replaceIterable()', iter)

const iterableType = iter.constructor.name
const iterableType = getIterableType(iter)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To se klidně mohl jen upravit ten switch tady.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no já potřebuju ten string pro tu serializaci, takže jsem to udělal přes metodu

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ach tak, jasně, jsem vůl. Ok.

if (!iterableType) {
throw new Error(`Cannot find type of iterable: ${iter}`)
}

switch (iterableType) {
case 'List':
case 'Set':
Expand All @@ -156,13 +185,6 @@ function replaceIterable(iter, replaceChild) {
mapData.push([ key, replaceChild(key, value) ])
})
return { "__iterable": iterableType, "data": mapData }

default:
const iterData = {}
iter.forEach((value, key) => {
iterData[key] = replaceChild(key, value)
})
return { "__iterable": iterableType, "data": iterData }
}
}

Expand Down