<commit_before>/*
 * @flow
 */

import {
  AuthorizationApi
} from 'loom-data';

import {
  Observable
} from 'rxjs';

import {
  combineEpics
} from 'redux-observable'

import * as PermissionsActionTypes from './PermissionsActionTypes';
import * as PermissionsActionFactory from './PermissionsActionFactory';
import AsyncActionFactory from '../async/AsyncActionFactory';

import {
  STATUS as ASYNC_STATUS
} from '../async/AsyncStorage';

import {
  deserializeAuthorization,
  createStatusAsyncReference
} from './PermissionsStorage';

import type {
  AccessCheck,
  PermissionsRequest,
  AclKey,
  Status
} from './PermissionsStorage'

import Api from '../Api';

function updateStatuses(statuses :Status[]) {
  return Observable.from(Api.updateStatuses(statuses))
    .mergeMap(response => {
      const tuples = statuses.map(status => [createStatusAsyncReference(status.aclKey), status]);
      return tuples.map(tuple => AsyncActionFactory.updateAsyncReference(tuple[0], tuple[1]));
    });
}

function updateStatusesEpic(action$) {
  return action$.ofType(PermissionsActionTypes.UPDATE_STATUSES)
    .pluck('statuses')
    .mergeMap(updateStatuses)
}

function loadStatuses(reqStatus :string, aclKeys :AclKey[]) {
  const references = aclKeys.map(createStatusAsyncReference);
  return Observable.merge(
    Observable.from(references)
      .map(AsyncActionFactory.asyncReferenceLoading),

    Observable.of([{
      aclKey: aclKeys[0],
      principal: {
        type: 'USER',
        id: 'auth0|57e4b2d8d9d1d194778fd5b6'
      },
      permissions: ['READ'],
      status: 'SUBMITTED'
    }])
      .mergeMap(statuses => {
        const statusByReferenceId = {};
        statuses.forEach(status => {
          statusByReferenceId[createStatusAsyncReference(status.aclKey).id] = status;
        });

        return references.map(reference => {
          const status = statusByReferenceId[reference.id];
          const value = status ? status : ASYNC_STATUS.NOT_FOUND;
          return AsyncActionFactory.updateAsyncReference(reference, value);<commit_msg>Removed hardcoded request<commit_after>/*
 * @flow
 */

import {
  AuthorizationApi
} from 'loom-data';

import {
  Observable
} from 'rxjs';

import {
  combineEpics
} from 'redux-observable'

import * as PermissionsActionTypes from './PermissionsActionTypes';
import * as PermissionsActionFactory from './PermissionsActionFactory';
import AsyncActionFactory from '../async/AsyncActionFactory';

import {
  STATUS as ASYNC_STATUS
} from '../async/AsyncStorage';

import {
  deserializeAuthorization,
  createStatusAsyncReference
} from './PermissionsStorage';

import type {
  AccessCheck,
  PermissionsRequest,
  AclKey,
  Status
} from './PermissionsStorage'

import Api from '../Api';

function updateStatuses(statuses :Status[]) {
  return Observable.from(Api.updateStatuses(statuses))
    .mergeMap(response => {
      const tuples = statuses.map(status => [createStatusAsyncReference(status.aclKey), status]);
      return tuples.map(tuple => AsyncActionFactory.updateAsyncReference(tuple[0], tuple[1]));
    });
}

function updateStatusesEpic(action$) {
  return action$.ofType(PermissionsActionTypes.UPDATE_STATUSES)
    .pluck('statuses')
    .mergeMap(updateStatuses)
}

function loadStatuses(reqStatus :string, aclKeys :AclKey[]) {
  const references = aclKeys.map(createStatusAsyncReference);
  return Observable.merge(
    Observable.from(references)
      .map(AsyncActionFactory.asyncReferenceLoading),

    Observable.from(Api.getStatus(reqStatus, aclKeys))
      .mergeMap(statuses => {
        const statusByReferenceId = {};
        statuses.forEach(status => {
          statusByReferenceId[createStatusAsyncReference(status.aclKey).id] = status;
        });

        return references.map(reference => {
          const status = statusByReferenceId[reference.id];
          const value = status ? status : ASYNC_STATUS.NOT_FOUND;
          return AsyncActionFactory.updateAsyncReference(reference, value);
{'fraction_non_alphanumeric': 0.11497995991983968, 'fraction_numerical': 0.005260521042084168, 'mean_word_length': 4.112676056338028, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1780512', 'n_tokens_mistral': 1152, 'n_tokens_neox': 1161, 'n_words': 221}