JSPM

json-atom

1.2.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2
  • Score
    100M100P100Q20902F
  • License MIT

Deep Immutable Composite Map, for the modern reactive functional programmer in ES2020+

Package Exports

  • json-atom

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 (json-atom) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

master develop npm
Build Status Build Status npm version

json-atom

    const {get, set, apply} = require('json-atom');
    const data = {
        user: {
            contact: {
                home: {
                    number: 11111
                }, mobile: {
                    number: 22222
                }
            },
            posts: [
                {content: 'Hello World!', likes: 10},
                {content: 'Goodbye World!', likes: 1}
            ]
        }
    };

    let result = get('$.user.contact.home.number')(data);
    // 11111

    result = get('$.user.contact["home","mobile"].number')(data);
    // {home: 11111, mobile: 22222}

    result = set('$.user.contact["home","mobile"].number')(99999)(data)

    // set is Immutable, data hasn't been modified, a new refernece is returned
    // lenses powering json-atom effectively behave like HAMT
    // They only create new objects for the nodes from root to path, the rest of the structure is shared.

    // {"user":{"contact":{"home":{"number":99999},"mobile":{"number":99999}},"posts":[{"content":"Hello World!","likes":10},{"content":"Goodbye World!","likes":1}]}}

    // number fields under both branches, namely 'home' AND 'mobile' are both set to value in the new object reference






Possible use cases

  • Redux Store Like Behavior around any JSON reference
  • Immutable deep manipulation of JSON data

Run the tests

npm test

FAQs

Build Targets

Currently the following target build environments are configured for babel-preset-env plugin

 "targets": {
   "node": 4.3,
   "browsers": ["last 10 versions", "ie >= 7"]
 }

In case this turns out to be not generous enough, more backward compatible babel transpilation targets would be added.

Roadmap

  • bigger and better
  • rule'em all

Contributing

See CONTRIBUTING.md

License

MIT