Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion .github/workflows/gh-pages.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Generate GitHub Pages Example
name: Generate GitHub Pages

on:
push:
Expand Down
20 changes: 11 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,16 +355,18 @@ class LightMap extends Map
// TODO: check for circular references
toObject()
{
return this.reduce(
( r, [ k, v ] ) => {
if ( v instanceof LightMap ) {
v = v.toObject();
}
const
obj = Object.fromEntries( this ),
keys = Object.keys( obj );

for ( let i = 0; i < keys.length; i++ ) {
const key = keys[ i ];
if ( obj[ key ] instanceof Map ) {
obj[ key ] = obj[ key ].toObject();
}
}

r[ k ] = v;
return r;
}, {}
);
return obj;
}

toJSON()
Expand Down
12 changes: 12 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,18 @@ describe( 'LightMap', () => {
() => expect( Object.prototype.toString.call( new LightMap() ) ).to.eq( '[object LightMap]' )
);

it( 'Symbol.species should equal Map',
() => {
const
a = new LightMap( [ [ 'a', 1 ], [ 'a', 2 ] ] ),
b = new Map( [ [ 'a', 1 ], [ 'a', 2 ] ] );

expect( LightMap[ Symbol.species ] ).to.eq( Map );
expect( a instanceof LightMap[ Symbol.species ] ).to.eq( true );
expect( b instanceof LightMap[ Symbol.species ] ).to.eq( true );
}
);

describe( 'Symbol.hasInstance', () => {
it( 'should be false if instance of Map', () => {
expect( new Map() instanceof LightMap ).to.eq( false );
Expand Down