All files / src/reactivity map.js

94.11% Statements 32/34
87.5% Branches 7/8
100% Functions 3/3
93.93% Lines 31/33

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 342x 2x 2x 2x 2x 2x 2x 11x 1x 1x 10x 10x 10x 10x 10x 2x 2x 3x     3x 3x 2x 2x 9x 1x 1x 8x 8x 8x 9x 2x 2x  
import { make_reactive, NOTIFY_WITH_ALL_PARAMS } from './utils.js';
 
export const ReactiveMap = make_reactive(Map, {
	write_properties: ['clear', 'delete', 'set'],
	read_properties: ['get', 'keys', 'has'],
	interceptors: {
		set: (notify_read_methods, value, property, ...params) => {
			if (value.get(params[0]) === params[1]) {
				return false;
			}
			if (!value.has(params[0])) {
				notify_read_methods(['keys']);
			}
			notify_read_methods(['get', 'has'], params[0]);
			return true;
		},
		clear: (notify_read_methods, value, property, ...params) => {
			if (value.size === 0) {
				return false;
			}
			notify_read_methods(['get', 'keys', 'has'], NOTIFY_WITH_ALL_PARAMS);
			return true;
		},
		delete: (notify_read_methods, value, property, ...params) => {
			if (!value.has(params[0])) {
				return false;
			}
			notify_read_methods(['get', 'has'], params[0]);
			notify_read_methods(['keys']);
			return true;
		}
	}
});