UNPKG

540 Btext/coffeescriptView Raw
1classMapId = 0
2
3# Counts seen classes to identify uniqueness (in at least a single instance).
4# This is needed because when using a normal object to create the mapping, the
5# class (ie: its name and constructor) are cast to a string, which may conflict.
6class ClassMap
7 constructor: ->
8 @_nextId = 1
9 @_classes = {}
10 @_field = "_honk_clsid_#{classMapId++}"
11
12 get: (cls) ->
13 @_classes[cls[@_field]]
14
15 set: (cls, instance) ->
16 cls[@_field] or= @_nextId++
17 @_classes[cls[@_field]] = instance
18
19module.exports = ClassMap