JSPM

immutable-map-symbol-preprocessor

0.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q20826F
  • License GPL-2.0

A way to create Immutable Maps from javascript objects that contain symbols as keys.

Package Exports

  • immutable-map-symbol-preprocessor

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (immutable-map-symbol-preprocessor) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Immutable Map Symbol Preprocessor

version 0.0.1, March 2, 2018 Allows the creation of Immutable maps from JavaScript objects that contain Symbols as keys.

While Immutable Maps can be created that use Symbols as keys, they do not allow this by just passing a JavaScript object into the constructor.

So Immutable supports this:

    const SY = Symbol('SY');
    const map = Map([[SY, 22]]);
    map.get(SY);// 22

Immutable does NOT support this:

    const SY = Symbol('SY');
    const data = { [SY]: 22 }
    const map = Map(data);
    map.get(SY) // undefined

This library contains two functions to help with this.

createMap: returns a Map from a JavaScript object that has symbols as keys. This does not create deep nested maps. createMapDeep: same as above, but allows for nesting;

createMap Example

    import { createMap } from 'immutable-map-symbol-preprocessor';

    const data = { [SY]: 22 }
    const map = createMap(data);

createMapDeep Example

    import { createMapDeep } from 'immutable-map-symbol-preprocessor';

    const data = { [SY]: 22, more: {one: 2}, [MORE]: {two: 4}}
    const map = createMapDeep(data);

alternative imports/require

    import createMap from 'immutable-map-symbol-preprocessor/create-map';
    import createMapDeep from 'immutable-map-symbol-preprocessor/create-map-deep'

Of course, you can use createMapDeep on a non-nested object. The first version, however is lighter and should be more performant.

Random Note.

Support for symbols in the constructor was the topic of this pull request on the Immutable github page. You may wish to visit that page if you want to see this made a permanent feature of the Immutable map library.