<commit_before>import {Observable} from 'rxjs/Observable';
import {Action} from './flux-action';
import {NextNow, NextMessageFromFalcorPage1, NextMessageFromFalcorPage2, NextDocumentsFromFalcorPage3} from './flux-action';
import 'rxjs/add/operator/scan';

import { getValueFromJsonGraph, getArrayFromJsonGraph } from '../app/falcor-utils';

// 現在日時を更新するReducer。
export function nowStateReducer(initState: number, dispatcher$: Observable<Action>): Observable<number> {
  return dispatcher$.scan((datetime: number, action: Action) => {
    if (action instanceof NextNow) {
      return action.datetime;
    } else {
      return datetime;
    }
  }, initState);
}

// Falcorを通してデータを取得するReducer。戻り値がObservable<Promise<any>>になるのが特徴。
export function messageStateReducerPage1(initState: Promise<string>, dispatcher$: Observable<Action>, falcorModel: any): Observable<Promise<string>> {
  return dispatcher$.scan((message: Promise<string>, action: Action) => {
    if (action instanceof NextMessageFromFalcorPage1) {
      return new Promise<string>(resolve => {
        falcorModel
          .get(action.falcorQuery)
          .then(jsonGraph => {
            console.log(JSON.stringify(jsonGraph, null, 2));
            const message = getValueFromJsonGraph(jsonGraph, ['json', ...action.falcorQuery], '?????') as string;
            resolve(message);
          });
      });
    } else {
      return message;
    }
  }, initState);
}

// Falcorを通してデータを取得するReducer。戻り値がObservable<Promise<any>>になるのが特徴。
export function messageStateReducerPage2(initState: Promise<string>, dispatcher$: Observable<Action>, falcorModel: any): Observable<Promise<string>> {
  return dispatcher$.scan((message: Promise<string>, action: Action) => {
    if (action instanceof NextMessageFromFalcorPage2) {
      return new Promise<string>(resolve => {
        falcorModel
          .get(action.falcorQuery)
          .then(jsonGraph => {
            console.log(JSON.stringify(jsonGraph, null, 2));
            const message = getValueFromJsonGraph(jsonGraph, ['json', ...action.falcorQuery], '?????') as string;
            resolve(message);
          });
      });
    } else {
      return message;
    }
  }, initState);
}

// Falcorを通してデータを取得するReducer。戻り値がObservable<Promise<any>>になるのが特徴。
export function documentsStateReducerPage3(initState: Promise<{}[]>, dispatcher$: Observable<Action>, falcorModel: any): Observable<Promise<{}[]>> {
  return dispatcher$.scan((message: Promise<{}[]>, action: Action) => {
    if (action instanceof NextDocumentsFromFalcorPage3) {
      return new Promise<{}[]>(resolve => {
        falcorModel
          .get(action.falcorQuery)
          .then(jsonGraph => {
            console.log(JSON.stringify(jsonGraph, null, 2));
            const documents = getArrayFromJsonGraph(jsonGraph, ['json', ...action.targetLayerArray], []);
            console.log(documents);
            resolve(documents);
          });
      });
    } else {
      return message;
    }
  }, initState);
}<commit_msg>Fixed<commit_after>import {Observable} from 'rxjs/Observable';
import {Action} from './flux-action';
import {NextNow, NextMessageFromFalcorPage1, NextMessageFromFalcorPage2, NextDocumentsFromFalcorPage3} from './flux-action';
import 'rxjs/add/operator/scan';

import { getValueFromJsonGraph, getArrayFromJsonGraph } from '../app/falcor-utils';

// 現在日時を更新するReducer。
export function nowStateReducer(initState: number, dispatcher$: Observable<Action>): Observable<number> {
  return dispatcher$.scan((datetime: number, action: Action) => {
    if (action instanceof NextNow) {
      return action.datetime;
    } else {
      return datetime;
    }
  }, initState);
}

// Falcorを通してデータを取得するReducer。戻り値がObservable<Promise<any>>になるのが特徴。
export function messageStateReducerPage1(initState: Promise<string>, dispatcher$: Observable<Action>, falcorModel: any): Observable<Promise<string>> {
  return dispatcher$.scan((message: Promise<string>, action: Action) => {
    if (action instanceof NextMessageFromFalcorPage1) {
      return new Promise<string>(resolve => {
        falcorModel
          .get(action.falcorQuery)
          .then(jsonGraph => {
            console.log(JSON.stringify(jsonGraph, null, 2));
            const message = getValueFromJsonGraph(jsonGraph, ['json', ...action.falcorQuery], '?????') as string;
            resolve(message);
          });
      });
    } else {
      return message;
    }
  }, initState);
}

// Falcorを通してデータを取得するReducer。戻り値がObservable<Promise<any>>になるのが特徴。
export function messageStateReducerPage2(initState: Promise<string>, dispatcher$: Observable<Action>, falcorModel: any): Observable<Promise<string>> {
  return dispatcher$.scan((message: Promise<string>, action: Action) => {
    if (action instanceof NextMessageFromFalcorPage2) {
      return new Promise<string>(resolve => {
        falcorModel
          .get(action.falcorQuery)
          .then(jsonGraph => {
            console.log(JSON.stringify(jsonGraph, null, 2));
            const message = getValueFromJsonGraph(jsonGraph, ['json', ...action.falcorQuery], '?????') as string;
            resolve(message);
          });
      });
    } else {
      return message;
    }
  }, initState);
}

// Falcorを通してデータを取得するReducer。戻り値がObservable<Promise<any>>になるのが特徴。
export function documentsStateReducerPage3(initState: Promise<{}[]>, dispatcher$: Observable<Action>, falcorModel: any): Observable<Promise<{}[]>> {
  return dispatcher$.scan((documents: Promise<{}[]>, action: Action) => {
    if (action instanceof NextDocumentsFromFalcorPage3) {
      return new Promise<{}[]>(resolve => {
        falcorModel
          .get(action.falcorQuery)
          .then(jsonGraph => {
            console.log(JSON.stringify(jsonGraph, null, 2));
            const documents = getArrayFromJsonGraph(jsonGraph, ['json', ...action.targetLayerArray], []);
            resolve(documents);
          });
      });
    } else {
      return documents;
    }
  }, initState);
}
{'fraction_non_alphanumeric': 0.13931681178834562, 'fraction_numerical': 0.004018754186202277, 'mean_word_length': 3.6123552123552125, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 75, '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': '3421279', 'n_tokens_mistral': 1867, 'n_tokens_neox': 1789, 'n_words': 327}