-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Replace WeakMap with object This update replaces the WeakMap with a regular Object for the cache within `create-emotion` core. This is to improve IE11 support without adding a (bloated) polyfill. * Revert "Replace WeakMap with object" This reverts commit 563004f. * Implement a light weight WeakMap polyfill from Google
- Loading branch information
Jon Quach
committed
Jan 17, 2019
1 parent
2ae0ab9
commit 7def3f7
Showing
3 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright 2012 The Polymer Authors. All rights reserved. | ||
* Use of this source code is governed by a BSD-style | ||
* license that can be found in the LICENSE file. | ||
*/ | ||
|
||
if (typeof WeakMap === 'undefined') { | ||
;(function() { | ||
var defineProperty = Object.defineProperty | ||
var counter = Date.now() % 1e9 | ||
|
||
var WeakMap = function() { | ||
this.name = '__st' + ((Math.random() * 1e9) >>> 0) + (counter++ + '__') | ||
} | ||
|
||
WeakMap.prototype = { | ||
set: function(key, value) { | ||
var entry = key[this.name] | ||
if (entry && entry[0] === key) entry[1] = value | ||
else | ||
defineProperty(key, this.name, { | ||
value: [key, value], | ||
writable: true, | ||
}) | ||
return this | ||
}, | ||
get: function(key) { | ||
var entry | ||
return (entry = key[this.name]) && entry[0] === key | ||
? entry[1] | ||
: undefined | ||
}, | ||
delete: function(key) { | ||
var entry = key[this.name] | ||
if (!entry) return false | ||
var hasValue = entry[0] === key | ||
entry[0] = entry[1] = undefined | ||
return hasValue | ||
}, | ||
has: function(key) { | ||
var entry = key[this.name] | ||
if (!entry) return false | ||
return entry[0] === key | ||
}, | ||
} | ||
|
||
window.WeakMap = WeakMap | ||
})() | ||
} |