public set()

in packages/geofire/src/GeoFire.ts [86:119]


  public set(keyOrLocations: string | any, location?: Geopoint): Promise<any> {
    let locations;
    if (typeof keyOrLocations === 'string' && keyOrLocations.length !== 0) {
      // If this is a set for a single location, convert it into a object
      locations = {};
      locations[keyOrLocations] = location;
    } else if (typeof keyOrLocations === 'object') {
      if (typeof location !== 'undefined') {
        throw new Error('The location argument should not be used if you pass an object to set().');
      }
      locations = keyOrLocations;
    } else {
      throw new Error('keyOrLocations must be a string or a mapping of key - location pairs.');
    }

    const newData = {};

    Object.keys(locations).forEach((key) => {
      validateKey(key);

      const location: Geopoint = locations[key];
      if (location === null) {
        // Setting location to null is valid since it will remove the key
        newData[key] = null;
      } else {
        validateLocation(location);

        const geohash: string = geohashForLocation(location);
        newData[key] = encodeGeoFireObject(location, geohash);
      }
    });

    return this._firebaseRef.update(newData);
  }