With the availability of constants and Symbols you could easily create what
SHOULD be a memory efficient event library.


On Thu, Jul 11, 2013 at 3:04 PM, Andrea Giammarchi <
[email protected]> wrote:

> trivial like ... 2 weak maps + a set for a single event ?
>
> ```javascript
> obj.on(evt, handler);
> ```
>
> .. internals ...
>
> ```javascript
> // wm as private internal generic WeakMap
> if (!wm.has(obj)) {
>   // creates related WeakMap
>   wm.set(obj, new WeakMap);
> }
> if (!wm.get(obj).has(evt)) {
>   wm.get(obj).set(evt, new Set);
> }
> wm.get(obj).get(evt).add(handler);
> ```
>
> I have the feeling it's very true in JS world nobody ever thinks about RAM
> and GC ^_^
>
> That said, it becomes over complicated for non concrete reason/use case if
> we have strings since AFAIK WeakMap does not accept strings as key.
>
> For all this time the event type as string has blocked like ... nobody
> ever ? I wonder again what's the benefit then to instantly over complicate
> an API at this stage instead of looking around what worked already for
> everyone.
>
> Maybe it's me not seeing the power of objects as events.
>
> br
>
>
>
> On Thu, Jul 11, 2013 at 2:32 PM, Rick Waldron <[email protected]>wrote:
>
>>
>>
>>
>> On Thu, Jul 11, 2013 at 4:45 PM, Andrea Giammarchi <
>> [email protected]> wrote:
>>
>>> I would simplify saying that symbols can be used as well as strings ? I
>>> don't see any usefulness into using an object as event type and I think if
>>> we start olready over-engineered/complicated this will never see the light
>>> in any spec which is a lost/lost if you ask me
>>>
>>
>> It's trivial if an Emitter uses something like [[MapData]] or
>> [[WeakMapData]] as it's internal data property for event storage.
>>
>>
>> Rick
>>
>>
>
> _______________________________________________
> es-discuss mailing list
> [email protected]
> https://mail.mozilla.org/listinfo/es-discuss
>
>


-- 
- Matthew Robb
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to