mapSet.js 663 B

12345678910111213141516171819202122232425262728
  1. import Map from './Map';
  2. import assocSet from './assocSet';
  3. import hashSet from './hashSet';
  4. import isKeyable from './isKeyable';
  5. /**
  6. * Sets the map `key` to `value`.
  7. *
  8. * @private
  9. * @name set
  10. * @memberOf MapCache
  11. * @param {string} key The key of the value to set.
  12. * @param {*} value The value to set.
  13. * @returns {Object} Returns the map cache object.
  14. */
  15. function mapSet(key, value) {
  16. var data = this.__data__;
  17. if (isKeyable(key)) {
  18. hashSet(typeof key == 'string' ? data.string : data.hash, key, value);
  19. } else if (Map) {
  20. data.map.set(key, value);
  21. } else {
  22. assocSet(data.map, key, value);
  23. }
  24. return this;
  25. }
  26. export default mapSet;