Skip to content

Commit

Permalink
Merge pull request #1 from NodeGuy/List
Browse files Browse the repository at this point in the history
Add basic List support.
  • Loading branch information
zackify authored Aug 2, 2016
2 parents 81f2109 + 84e7171 commit 496abe9
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 21 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
lib
node_modules
2 changes: 1 addition & 1 deletion circle.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
machine:
node:
version: 5.6.0
version: 6.1.0
17 changes: 0 additions & 17 deletions index.js

This file was deleted.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "immutable-proxy",
"version": "0.0.1",
"description": "access immutable values more easily",
"main": "index.js",
"main": "lib/index.js",
"peerDependencies": {
"immutable": "^3.7.6"
},
Expand All @@ -19,7 +19,7 @@
},
"scripts": {
"test": "mocha tests --compilers js:babel-register --recursive --harmony_shipping ",
"build": "babel src/index.js --out-file index.js && npm run build-umd && npm run build-min",
"build": "babel src -d lib && npm run build-umd && npm run build-min",
"build-umd": "NODE_ENV=production webpack src/index.js umd/index.js",
"build-min": "NODE_ENV=production webpack -p src/index.js umd/index.min.js"
},
Expand Down
4 changes: 3 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import Immutable from 'immutable'
import List from './list'
import Map from './map'

module.exports = {
...Immutable,
List,
Map
}
}
15 changes: 15 additions & 0 deletions src/list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { List } from 'immutable'

export default initialData => {
const immutableList = List(initialData)

return new Proxy(immutableList, {
get: (proxy, name) => {
const immutableName = name === 'length'
? 'size'
: name

return immutableList.get(immutableName) || immutableList[immutableName]
}
})
}
14 changes: 14 additions & 0 deletions tests/list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import List from '../src/list'
import { expect } from 'chai'

describe('List Proxy', () => {
it('should access value without calling .get', () => {
const data = List([1, 2, 3])
expect(data[1]).to.equal(2)
})

it('should provide the "length" property', () => {
const data = List([1, 2, 3])
expect(data.length).to.equal(3)
})
})

0 comments on commit 496abe9

Please sign in to comment.