How to use es6-weak-map - 8 common examples

To help you get started, we’ve selected a few es6-weak-map examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github azu / idempotent-bind / src / idempotent-bind.js View on Github external
// LICENSE : MIT
"use strict";
import WeakMap from "es6-weak-map"
var map = new WeakMap();
// for WeakMap Reference, not to use bind
function getGlobal() {
    if (typeof global !== "undefined") {
        return global;
    }
    if (typeof window !== "undefined") {
        return window;
    }
    // web worker
    if (typeof self !== "undefined") {
        return self;
    }
}
function createBind(target, thisArg) {
    var binding = target.bind(thisArg);
    var secondMap = map.get(target);
github azu / idempotent-bind / src / idempotent-bind.js View on Github external
function createBind(target, thisArg) {
    var binding = target.bind(thisArg);
    var secondMap = map.get(target);
    if (secondMap == null) {
        secondMap = new WeakMap();
        map.set(target, secondMap);
    }
    // bind(bind(f, this), this) = binding
    map.set(binding, secondMap);
    // bind(f, this) = binding
    secondMap.set(thisArg, binding);
    return binding;
}
function releaseBind(secondMap, thisArg) {
github ZeeCoder / container-query / packages / container-query / src / containerRegistry.js View on Github external
// @flow
import WeakMap from "es6-weak-map";
import type { RegistryData } from "../flow/types";

const containerRegistry: WeakMap = new WeakMap();

export default {
  set: function(element: Element | Node, data: RegistryData) {
    containerRegistry.set(element, data);
  },

  get: function(element: Element | Node) {
    return containerRegistry.get(element);
  },

  has: function(element: Element | Node) {
    return containerRegistry.has(element);
  },

  delete: function(element: Element | Node) {
    containerRegistry.delete(element);
github sx1989827 / DOClever / Desktop / node_modules / escope / src / scope-manager.js View on Github external
constructor(options) {
        this.scopes = [];
        this.globalScope = null;
        this.__nodeToScope = new WeakMap();
        this.__currentScope = null;
        this.__options = options;
        this.__declaredVariables = new WeakMap();
    }
github Wildhoney / Leaflet.FreeDraw / src / FreeDraw.js View on Github external
import { FeatureGroup, Point } from 'leaflet';
import { select } from 'd3-selection';
import { line, curveMonotoneX } from 'd3-shape';
import Set from 'es6-set';
import WeakMap from 'es6-weak-map';
import Symbol from 'es6-symbol';
import { updateFor } from './helpers/Layer';
import { createFor, removeFor, clearFor } from './helpers/Polygon';
import { CREATE, EDIT, DELETE, APPEND, EDIT_APPEND, NONE, ALL, modeFor } from './helpers/Flags';
import simplifyPolygon from './helpers/Simplify';

/**
 * @constant polygons
 * @type {WeakMap}
 */
export const polygons = new WeakMap();

/**
 * @constant defaultOptions
 * @type {Object}
 */
export const defaultOptions = {
    mode: ALL,
    smoothFactor: 0.3,
    elbowDistance: 10,
    simplifyFactor: 1.1,
    mergePolygons: true,
    concavePolygon: true,
    maximumPolygons: Infinity,
    notifyAfterEditExit: false,
    leaveModeAfterCreate: false,
    strokeWidth: 2
github ZeeCoder / container-query / packages / react-container-query / src / ResizeObserver.js View on Github external
import React, { Component } from "react";
import ReactDOM from "react-dom";
import PropTypes from "prop-types";
import ResizeObserver from "resize-observer-polyfill";
import WeakMap from "es6-weak-map";

const registry = new WeakMap();

const resizeObserver = new ResizeObserver(entries => {
  entries.forEach(entry => {
    const instance = registry.get(entry.target);
    if (!instance) {
      return;
    }

    instance.handleResize(entry.contentRect);
  });
});

export default class ResizeObserverComponent extends Component {
  constructor(props) {
    super(props);
github Wildhoney / Keo / src / keo.js View on Github external
* @constant propertyBlacklist
 * @type {String[]}
 */
const propertyBlacklist = ['getInitialState', 'mixins'];

/**
 * @constant propertyWhitelist
 * @type {String[]}
 */
const propertyWhitelist = ['id', 'props', 'context', 'nextProps', 'prevProps', 'dispatch'];

/**
 * @constant identityStore
 * @type {WeakMap}
 */
const identityStore = new WeakMap();

/**
 * @method identityFor
 * @param {Object} context
 * @return {Object}
 */
const identityFor = context => {

    return identityStore.get(context) || (() => {
        const id = Symbol('keo/component');
        identityStore.set(context, id);
        return id;
    })();

};
github sx1989827 / DOClever / Desktop / node_modules / escope / src / scope-manager.js View on Github external
constructor(options) {
        this.scopes = [];
        this.globalScope = null;
        this.__nodeToScope = new WeakMap();
        this.__currentScope = null;
        this.__options = options;
        this.__declaredVariables = new WeakMap();
    }

es6-weak-map

ECMAScript6 WeakMap polyfill

ISC
Latest version published 5 years ago

Package Health Score

65 / 100
Full package analysis

Popular es6-weak-map functions