immutable#OrderedMap JavaScript Examples

The following examples show how to use immutable#OrderedMap. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: authen.js    From React-Messenger-App with MIT License 6 votes vote down vote up
getMessagesFromChannel(channel) {

        let messages = new OrderedMap();


        if (channel) {


            channel.messages.forEach((value, key) => {


                const message = this.messages.get(key);

                messages = messages.set(key, message);

            });

        }

        return messages.valueSeq();
    }
Example #2
Source File: authen.js    From React-Messenger-App with MIT License 6 votes vote down vote up
getMembersFromChannel(channel) {

        let members = new OrderedMap();

        if (channel) {


            channel.members.forEach((value, key) => {


                const userId = `${key}`;
                const user = this.users.get(userId);

                const loggedUser = this.getCurrentUser();

                if (_.get(loggedUser, '_id') !== _.get(user, '_id')) {
                    members = members.set(key, user);
                }


            });
        }

        return members.valueSeq();
    }
Example #3
Source File: authen.js    From React-Messenger-App with MIT License 6 votes vote down vote up
constructor(appComponent) {

        this.app = appComponent;
        this.service = new Service();
        this.messages = new OrderedMap();
        this.channels = new OrderedMap();
        this.activeChannelId = null;


        this.token = this.getTokenFromLocalStore();

        this.user = this.getUserFromLocalStorage();
        this.users = new OrderedMap();

        this.search = {
            users: new OrderedMap(),
        }


        this.realtime = new Realtime(this);

        this.fetchUserChannels();


    }
Example #4
Source File: metric-feeder.js    From ThreatMapper with Apache License 2.0 5 votes vote down vote up
makeOrderedMap = OrderedMap
Example #5
Source File: ExperimentCreateDialog.js    From minerva with MIT License 4 votes vote down vote up
ExperimentCreateDialog = (props) => {
  const [isUploading, setIsUploading] = useState(false)
  const [uploadProgress, setUploadProgress] = useState(0)
  const [experimentName, setExperimentName] = useState('')
  const [basicConfig, setBasicConfig] = useState(OrderedMap({}))
  const [advancedConfig, setAdvancedConfig] = useState(OrderedMap({}))
  const [isShowingAdvancedConfig, setIsShowingAdvancedConfig] = useState(false)
  const { status, createExperiment, showErrorToast } = useContext(GlobalContext)

  const { dataset, project } = props
  const { algorithm } = project

  useEffect(() => {
    setExperimentName(`${algorithm.toUpperCase()}_${getTimestamp()}`)

    // Algorithm-specific configurations
    const { isDiscrete } = dataset
    const algoConfigs = isDiscrete ? DISCRETE_CONFIGS : CONTINUOUS_CONFIGS
    let algoConfig = OrderedMap(algoConfigs[algorithm])

    // Default option based on observation type
    const scaler = dataset.isImage ? 'pixel' : null
    let config = OrderedMap(COMMON_CONFIGS.basic_config).set('scaler', scaler)
    if (!dataset.isImage) {
      // Remove frame stacking option
      config = config.delete('n_frames')
    }

    // Apply algorithm-specific default parameters
    for (const key of algoConfig.keys()) {
      if (config.has(key)) {
        config = config.set(key, algoConfig.get(key))
        algoConfig = algoConfig.delete(key)
      }
    }

    setBasicConfig(config)

    const commonAdvancedConfig = COMMON_CONFIGS.advanced_config
    setAdvancedConfig(OrderedMap(commonAdvancedConfig).merge(algoConfig))
  }, [props.isOpen])

  const handleClose = () => {
    setUploadProgress(0)
    setBasicConfig(OrderedMap({}))
    setAdvancedConfig(OrderedMap({}))
    setExperimentName('')
    setIsShowingAdvancedConfig(false)
    props.onClose()
  }

  const handleSubmit = () => {
    // Quick validation
    if (experimentName === '') {
      return
    }

    setIsUploading(true)
    const progressCallback = (e) => {
      const progress = Math.round(e.loaded * 100 / e.total)
      setUploadProgress(progress)
    }

    // Concat basic configs and advanced configs
    const config = Object.assign(basicConfig.toJS(), advancedConfig.toJS())

    createExperiment(project.id, experimentName, config, progressCallback)
      .then((experiment) => {
        setIsUploading(false)
        handleClose()
        return experiment
      })
      .catch(() => showErrorToast('Failed to create experiment.'))
  }

  const handleBasicConfigChange = (key, value) => {
    setBasicConfig(basicConfig.set(key, value))
  }
  const handleAdvancedConfigChange = (key, value) => {
    setAdvancedConfig(advancedConfig.set(key, value))
  }

  return (
    <Dialog
      isOpen={props.isOpen}
      title='Run experiment'
      onConfirm={handleSubmit}
      onClose={handleClose}
      isUploading={isUploading}
      uploadProgress={uploadProgress}
    >
      <div>
        <FormRow>
          <TextFormUnderline
            value={experimentName}
            placeholder='EXPERIMENT NAME'
            onChange={(name) => setExperimentName(name)}
          />
        </FormRow>
        <ConfigForms
          config={basicConfig.toJS()}
          status={status}
          onChange={handleBasicConfigChange}
          dataset={dataset}
        />
        {!isShowingAdvancedConfig &&
          <div className='advanced-config-button'>
            <Button
              text='SHOW ADVANCED CONFIGURATIONS'
              onClick={() => setIsShowingAdvancedConfig(true)}
            />
          </div>}
        {isShowingAdvancedConfig &&
          <div className='advanced-config-button'>
            <Button
              text='HIDE ADVANCED CONFIGURATIONS'
              onClick={() => setIsShowingAdvancedConfig(false)}
            />
          </div>}
        {isShowingAdvancedConfig &&
          <ConfigForms
            config={advancedConfig.toJS()}
            status={status}
            onChange={handleAdvancedConfigChange}
            dataset={props.dataset}
          />}
      </div>
    </Dialog>
  )
}