-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update editor to parse the DOM to the post AT
- Loading branch information
Showing
3 changed files
with
98 additions
and
26 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,30 @@ | ||
// start at one to make the falsy semantics easier | ||
let uuidGenerator = 1; | ||
|
||
class ElementMap { | ||
constructor() { | ||
this._map = {}; | ||
} | ||
set(key, value) { | ||
let uuid = key.dataset.uuid; | ||
if (!uuid) { | ||
key.dataset.uuid = uuid = uuidGenerator++; | ||
} | ||
this._map[uuid] = value; | ||
} | ||
get(key) { | ||
if (key.dataset && key.dataset.uuid) { | ||
return this._map[key.dataset.uuid]; | ||
} | ||
return null; | ||
} | ||
remove(key) { | ||
if (!key.dataset.uuid) { | ||
throw new Error('tried to fetch a value for an element not seen before'); | ||
} | ||
delete this._map[key.dataset.uuid]; | ||
} | ||
|
||
} | ||
|
||
export default ElementMap; |