tc39 / proposal-policy-map-set

A TC39 proposal for Maps and Sets with cache replacement policies like LRU and LFU.
BSD 3-Clause "New" or "Revised" License
15 stars 2 forks source link

Constructor parameters: ordered or options bag? #10

Open js-choi opened 2 years ago

js-choi commented 2 years ago

Let’s assume that we make new classes rather than using Map and Set (see #8 and #5). Given that, we now have two or three possible parameters:

There are several API choices that I can think of:

new CacheMap('lru', [ 256, 'purgeable' ], entries)
new CacheMap('lru', { maxSize: 256, purgeable: true }, entries)
new CacheMap('lru', entries, { maxSize: 256, purgeable: true })
new CacheMap('lru', { maxSize: 256, purgeable: true, entries })
new CacheMap({ policy: 'lru', maxSize: 256, purgeable: true, entries })
ljharb commented 2 years ago

Why separate classes rather than a constructor options bag parameter to the existing Map and Set?

js-choi commented 2 years ago

Reusing Map and Set and extending them with option bags is another API option. I’ve tweaked this issue’s original post to say that this issue assumes that we’re going with separate classes as per #8 or #5.

I’m inclined to agree with https://github.com/tc39/proposal-policy-map-set/issues/1#issuecomment-1199766146, but we probably should talk about that more in #1.