├── .babelrc ├── .gitignore ├── .npmignore ├── README.md ├── circle.yml ├── example └── index.html ├── package.json ├── src ├── index.js ├── list.js └── map.js ├── tests ├── list.js └── map.js ├── umd ├── index.js └── index.min.js └── webpack.config.js /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["es2015"], 3 | "plugins": ["transform-object-rest-spread"] 4 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | lib 2 | node_modules 3 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | example 2 | src 3 | tests 4 | webpack.config.js 5 | .babelrc 6 | circle.yml -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ##Immutable Proxy 2 | 3 | A simple library that wraps around [immutable](https://facebook.github.io/immutable-js). Tired of doing `Map.get('item')`? With proxy support, you can do `Map.item`, like accessing regular objects! 4 | 5 | This is just the start. Only `Map` is supported right now. You can import any features that Immutable exposes through this package. 6 | 7 | ###Install 8 | 9 | ``` 10 | npm install immutable-proxy --save 11 | ``` 12 | 13 | ###Example 14 | 15 | ```js 16 | import Immutable from 'immutable-proxy' 17 | 18 | const data = Immutable.Map({first: 'yo'}) 19 | expect(data.first).to.equal('yo') 20 | 21 | //data.get('first') still works 22 | ``` -------------------------------------------------------------------------------- /circle.yml: -------------------------------------------------------------------------------- 1 | machine: 2 | node: 3 | version: 6.1.0 4 | -------------------------------------------------------------------------------- /example/index.html: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "immutable-proxy", 3 | "version": "0.0.2", 4 | "description": "access immutable values more easily", 5 | "main": "lib/index.js", 6 | "peerDependencies": { 7 | "immutable": "^3.7.6" 8 | }, 9 | "devDependencies": { 10 | "babel-cli": "^6.6.5", 11 | "babel-loader": "^6.2.4", 12 | "babel-plugin-transform-object-rest-spread": "^6.6.5", 13 | "babel-preset-es2015": "^6.6.0", 14 | "babel-register": "^6.7.2", 15 | "chai": "^3.5.0", 16 | "mocha": "^2.4.5", 17 | "webpack": "^1.12.14", 18 | "immutable": "^3.7.6" 19 | }, 20 | "scripts": { 21 | "test": "mocha tests --compilers js:babel-register --recursive --harmony_shipping ", 22 | "build": "babel src -d lib && npm run build-umd && npm run build-min", 23 | "build-umd": "NODE_ENV=production webpack src/index.js umd/index.js", 24 | "build-min": "NODE_ENV=production webpack -p src/index.js umd/index.min.js" 25 | }, 26 | "repository": { 27 | "type": "git", 28 | "url": "git+ssh://git@github.com/zackify/immutable-proxy.git" 29 | }, 30 | "author": "Zach Silveira", 31 | "license": "ISC", 32 | "bugs": { 33 | "url": "https://github.com/zackify/immutable-proxy/issues" 34 | }, 35 | "homepage": "https://github.com/zackify/immutable-proxy#readme" 36 | } 37 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import Immutable from 'immutable' 2 | import List from './list' 3 | import Map from './map' 4 | 5 | module.exports = { 6 | ...Immutable, 7 | List, 8 | Map 9 | } 10 | -------------------------------------------------------------------------------- /src/list.js: -------------------------------------------------------------------------------- 1 | import { List } from 'immutable' 2 | 3 | export default initialData => { 4 | const immutableList = List(initialData) 5 | 6 | return new Proxy(immutableList, { 7 | get: (proxy, name) => { 8 | const immutableName = name === 'length' 9 | ? 'size' 10 | : name 11 | 12 | return immutableList.get(immutableName) || immutableList[immutableName] 13 | } 14 | }) 15 | } 16 | -------------------------------------------------------------------------------- /src/map.js: -------------------------------------------------------------------------------- 1 | import { Map } from 'immutable' 2 | 3 | export default initialData => { 4 | const immutableMap = Map(initialData) 5 | 6 | return new Proxy(immutableMap, { 7 | get: (proxy, name) => immutableMap.get(name) || immutableMap[name] 8 | }) 9 | } -------------------------------------------------------------------------------- /tests/list.js: -------------------------------------------------------------------------------- 1 | import List from '../src/list' 2 | import { expect } from 'chai' 3 | 4 | describe('List Proxy', () => { 5 | it('should access value without calling .get', () => { 6 | const data = List([1, 2, 3]) 7 | expect(data[1]).to.equal(2) 8 | }) 9 | 10 | it('should provide the "length" property', () => { 11 | const data = List([1, 2, 3]) 12 | expect(data.length).to.equal(3) 13 | }) 14 | }) 15 | -------------------------------------------------------------------------------- /tests/map.js: -------------------------------------------------------------------------------- 1 | import Map from '../src/map' 2 | import { expect } from 'chai' 3 | 4 | describe('Map Proxy', () => { 5 | it('should access value without calling .get', () => { 6 | const data = Map({first: 'yo'}) 7 | expect(data.first).to.equal('yo') 8 | }) 9 | }) -------------------------------------------------------------------------------- /umd/index.min.js: -------------------------------------------------------------------------------- 1 | !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.ImmutableProxy=e():t.ImmutableProxy=e()}(this,function(){return function(t){function e(n){if(r[n])return r[n].exports;var i=r[n]={exports:{},id:n,loaded:!1};return t[n].call(i.exports,i,i.exports,e),i.loaded=!0,i.exports}var r={};return e.m=t,e.c=r,e.p="",e(0)}([function(t,e,r){"use strict";function n(t){return t&&t.__esModule?t:{"default":t}}var i=Object.assign||function(t){for(var e=1;e