Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Map #19

Merged
merged 4 commits into from
Jul 27, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix map construction
  • Loading branch information
davecoates committed Jul 27, 2016
commit 653c07ffa0c71ea329de22e275c8be04c4fcfc4f
8 changes: 3 additions & 5 deletions src/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,8 @@ export const Map = function(keyDescriptor, valueDescriptor, label) {
const type = new EntryType(keyType, valueType, label)

const MapType = function(value) {
const isThis = this instanceof MapType
const constructor = isThis ? this.constructor : MapType
const isMapType = this instanceof MapType
const constructor = isMapType ? this.constructor : MapType

if (value instanceof constructor) {
return value
Expand All @@ -262,9 +262,7 @@ export const Map = function(keyDescriptor, valueDescriptor, label) {
throw result
}

const isCall = isThis && construct.prototype === this

if (!isCall && isThis) {
if (isMapType && !this[$store]) {
this[$store] = result[$store]
this.size = result.size
} else {
Expand Down
2 changes: 2 additions & 0 deletions src/test/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ test('is persistent to updateIn', assert => {
assert.throws(() => m2.updateIn(['level1', 'a'], 5))
assert.throws(() => m2.updateIn(['level1', 5], 'a'))
assert.throws(() => m2.updateIn([1, 'a'], 'a'))
assert.deepEquals(m1.toJS(), {a: 'a', b: 'b'})
assert.deepEquals(m2.toJS(), {level1: {a: 'a', b: 'b'}})
assert.deepEquals(m3.toJS(), {level1: {a: 'aa', b: 'b'}})
assert.deepEquals(m4.toJS(), {level1: {a: 'aaaa', b: 'b'}})
})
Expand Down