superjson icon indicating copy to clipboard operation
superjson copied to clipboard

Add Function Support

Open nrdobie opened this issue 5 years ago • 0 comments

This would add support for Functions as values.

Proposed usage:

import SJSON, { registerFunction } from '@onedeadpixel/superjson'

// In application setup
registerFunction(SJSON)

const data = {
  myFunc: (status) => console.log('MY LOG:', status)
}

const jsonString = SJSON.stringify(data) // => {
//   "myFunc": {
//     "__sj_type": "Function",
//     "__sj_value": "(status) => console.log('MY LOG:', status)"
//    }
//  }

// JSON string sent to another memory instance

const data = SJSON.parse(jsonString) // => {
//   myFunc: (status) => console.log('MY LOG:', status)
// }

Possible Issues:

  • Functions could pose some level of security risk so they would not be enabled by default.

nrdobie avatar Jul 19 '19 15:07 nrdobie