Skip to content
Myr

refactor: traps for Maps and Sets

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by keenondrums · committed by Alec Larson · parent 4355b63 · Browse files · 1 file+15 added−17 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+15 added−17 removed

  • other:+15 added−17 removed

1 file+15 added−17 removed

modified:src/proxy.js+15 added-17 removed
179 unmodified lines
180/**181 * Map drafts182 */183184const mapTraps = {185 get(state, prop, receiver) {186 return mapGetters.hasOwnProperty(prop)187 ? mapGetters[prop](state, prop, receiver)188 : Reflect.get(state, prop, receiver)189 }190}184const mapGetters = {185 [DRAFT_STATE]: state => state,186 size: state => source(state).size,187 has(state, prop) {
56 unmodified lines
244 values: iterateMapValues,245 entries: iterateMapValues,246 [Symbol.iterator]: iterateMapValues247}248const mapTraps = makeTrapsForGetters(mapGetters)249250/** Map.prototype.values _-or-_ Map.prototype.entries */251function iterateMapValues(state, prop, receiver) {252 const getYieldable =
16 unmodified lines
269/**270 * Set drafts271 */272279const setTraps = {280 get(state, prop, receiver) {281 return setGetters.hasOwnProperty(prop)282 ? setGetters[prop](state, prop, receiver)283 : Reflect.get(state, prop, receiver)284 },285 ownKeys(state) {286 return Reflect.ownKeys(source(state))287 }288}273const setGetters = {274 [DRAFT_STATE]: state => state,275 size: state => source(state).size,276 has(state, prop) {
27 unmodified lines
304 values: iterateSetValues,305 entries: iterateSetValues,306 [Symbol.iterator]: iterateSetValues307}308const setTraps = makeTrapsForGetters(setGetters)309310function iterateSetValues(state, prop) {311 return () => {312 const iterator = source(state)[Symbol.iterator]()
76 unmodified lines
389 [Symbol.iterator]: () => self,390 next391 })392}393394function makeTrapsForGetters(getters) {395 return {396 get(state, prop, receiver) {397 return getters.hasOwnProperty(prop)398 ? getters[prop](state, prop, receiver)399 : Reflect.get(state, prop, receiver)400 },401 ownKeys(state) {402 return Reflect.ownKeys(source(state))403 }404 }405}