Skip to content

Commit 84e7171

Browse files
David BraunDavid Braun
authored andcommitted
Add basic List support.
1 parent cb10874 commit 84e7171

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

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)