Code cleanup for remote module
This commit is contained in:
parent
88fc4e9d05
commit
647a0c4e2b
2 changed files with 14 additions and 21 deletions
|
@ -33,14 +33,13 @@ valueToMeta = (sender, value, optimizeSimpleObject=false) ->
|
|||
# it.
|
||||
meta.id = objectsRegistry.add sender.getId(), value
|
||||
|
||||
meta.members = []
|
||||
meta.members.push {name: prop, type: typeof field} for prop, field of value
|
||||
meta.members = ({name, type: typeof field} for name, field of value)
|
||||
else if meta.type is 'buffer'
|
||||
meta.value = Array::slice.call value, 0
|
||||
else if meta.type is 'promise'
|
||||
meta.then = valueToMeta(sender, value.then.bind(value))
|
||||
meta.then = valueToMeta sender, value.then.bind(value)
|
||||
else if meta.type is 'error'
|
||||
meta = errorValueToMeta(value, meta)
|
||||
meta.members = plainObjectToMeta value
|
||||
else if meta.type is 'date'
|
||||
meta.value = value.getTime()
|
||||
else
|
||||
|
@ -49,12 +48,9 @@ valueToMeta = (sender, value, optimizeSimpleObject=false) ->
|
|||
|
||||
meta
|
||||
|
||||
# Convert Error into meta data.
|
||||
errorValueToMeta = (err, meta) ->
|
||||
Object.getOwnPropertyNames(err).reduce((obj, key) ->
|
||||
obj[key] = err[key]
|
||||
obj
|
||||
, meta)
|
||||
# Convert object to meta by value.
|
||||
plainObjectToMeta = (obj) ->
|
||||
Object.getOwnPropertyNames(obj).map (name) -> {name, value: obj[name]}
|
||||
|
||||
# Convert Error into meta data.
|
||||
exceptionToMeta = (error) ->
|
||||
|
|
|
@ -46,7 +46,7 @@ metaToValue = (meta) ->
|
|||
when 'array' then (metaToValue(el) for el in meta.members)
|
||||
when 'buffer' then new Buffer(meta.value)
|
||||
when 'promise' then Promise.resolve(then: metaToValue(meta.then))
|
||||
when 'error' then metaToError(meta)
|
||||
when 'error' then metaToPlainObject meta
|
||||
when 'date' then new Date(meta.value)
|
||||
when 'exception'
|
||||
throw new Error("#{meta.message}\n#{meta.stack}")
|
||||
|
@ -110,16 +110,13 @@ metaToValue = (meta) ->
|
|||
|
||||
ret
|
||||
|
||||
# Convert meta data from browser into Error.
|
||||
metaToError = (meta) ->
|
||||
Object.getOwnPropertyNames(meta).reduce((error, prop) ->
|
||||
Object.defineProperty(error, prop, {
|
||||
get: -> meta[prop],
|
||||
enumerable: false,
|
||||
configurable: false
|
||||
})
|
||||
error
|
||||
, new Error())
|
||||
# Construct a plain object from the meta.
|
||||
metaToPlainObject = (meta) ->
|
||||
obj = switch meta.type
|
||||
when 'error' then new Error
|
||||
else {}
|
||||
obj[name] = value for {name, value} in meta.members
|
||||
obj
|
||||
|
||||
# Browser calls a callback in renderer.
|
||||
ipc.on 'ATOM_RENDERER_CALLBACK', (id, args) ->
|
||||
|
|
Loading…
Reference in a new issue