Skip to content

Commit 496abe9

Browse files
authored
Merge pull request #1 from NodeGuy/List
Add basic List support.
2 parents 81f2109 + 84e7171 commit 496abe9

File tree

7 files changed

+37
-21
lines changed

7 files changed

+37
-21
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
lib
2+
node_modules

circle.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
machine:
22
node:
3-
version: 5.6.0
3+
version: 6.1.0

index.js

Lines changed: 0 additions & 17 deletions
This file was deleted.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "immutable-proxy",
33
"version": "0.0.1",
44
"description": "access immutable values more easily",
5-
"main": "index.js",
5+
"main": "lib/index.js",
66
"peerDependencies": {
77
"immutable": "^3.7.6"
88
},
@@ -19,7 +19,7 @@
1919
},
2020
"scripts": {
2121
"test": "mocha tests --compilers js:babel-register --recursive --harmony_shipping ",
22-
"build": "babel src/index.js --out-file index.js && npm run build-umd && npm run build-min",
22+
"build": "babel src -d lib && npm run build-umd && npm run build-min",
2323
"build-umd": "NODE_ENV=production webpack src/index.js umd/index.js",
2424
"build-min": "NODE_ENV=production webpack -p src/index.js umd/index.min.js"
2525
},

src/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import Immutable from 'immutable'
2+
import List from './list'
23
import Map from './map'
34

45
module.exports = {
56
...Immutable,
7+
List,
68
Map
7-
}
9+
}

src/list.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
}

tests/list.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
})

0 commit comments

Comments
 (0)