<commit_before>//import { searchGraph, searchPanel } from "../actions/panelView";

import Reflux from "reflux";
import Identifier from '../../model/Identifier';

import { setRootIdentifiers } from '../actions/application';

import Monitor from '../../model/Monitor';


export const PANEL_SEARCH = Symbol("PANEL_SEARCH");
export const GRAPH_SEARCH = Symbol("GRAPH_SEARCH");
export const DEFAULT_SEARCH = Symbol("DEFAULT_SEARCH");

var search = Reflux.createAction({
    asyncResult: true
});

export const searchGraph = function(identifier, params) {
    search(identifier, params, {context: GRAPH_SEARCH});
};

export const identifierSelect = function(identifier, columnIndex, params = {}) {
    search(identifier, params, {columnIndex, context: PANEL_SEARCH});
};

search.listen((identifier, params, options) => {
    identifier.search(params)
        .then(search.completed.bind(null, {identifier, params, ...options}))
        .catch(search.failed)
});

var storeUpdated = Reflux.createAction();

var storeDataUpdated = Reflux.createAction();

let updateMetadata = Reflux.createAction();

// TODO: This is for demo only
window.updateMetadata = updateMetadata;

export const globalStore = Reflux.createStore({
    getInitialState() {
        return {
            nodes: new Set(),
            edges: new Set()
        }
    },

    init() {
        this.state = this.getInitialState();
        this.listenTo(search.completed, this.onSearchCompleted);
        this.listenTo(updateMetadata, this.onMetadataUpdate);
        this.listenTo(setRootIdentifiers, this.setRootIdentifiers);

        this.monitor = new Monitor();
    },

    setRootIdentifiers(identifiers) {
        this.state = { nodes: new Set(identifiers), edges: new Set() };
        this._startMonitoring(identifiers);
        storeUpdated(this.state, {context: DEFAULT_SEARCH}, null);
    },

    onMetadataUpdate(identifier, metadata) {
        identifier.metadata = metadata;
        storeDataUpdated(this.state);
    },

    onSearchCompleted(options, result) {
        this.state = this._onSearchCompleted(result);
        storeUpdated(this.state, options, result);
    },

    _startMonitoring(identifiers) {
        this.monitor.listen(identifiers.map(i => i.name), i => {
            //Identifier.get(i.identifier);
            //console.log("monitoring", i);
        });
    },

    _onSearchCompleted({ identifiers, links }) {
        var { nodes, edges } = this.state;
        nodes = [...nodes];
        edges = [...edges];

        links = links.map((l) => {
            return {
                target: Identifier.get(l.target),
                source: Identifier.get(l.source),
                data: l
            }
        });

        nodes.push(...identifiers);
        edges.push(...links);

        this._startMonitoring(identifiers);

        return { nodes: new Set(nodes), edges: new Set(edges) };
    }

});

export const graphStore = Reflux.createStore({
    getInitialState() {
        return globalStore.state;
        //return {
        //    nodes: [],
        //    edges: []
        //}
    },

    init() {
        this.listenTo(storeUpdated, this.onStoreUpdated);
        this.listenTo(storeDataUpdated, this.onStoreUpdated);
    },

    onStoreUpdated(state, options, results) {
        this.trigger(state);
    }
});

export const panelStore = Reflux.createStore({
    getInitialState() {
        return {
            items: []
        }
    },

    init() {
        this.state = this.getInitialState();
        this.listenTo(storeUpdated, this.onStoreSearchUpdated);
    },

    onStoreSearchUpdated(state, options, results = null) {
        if (options.context === PANEL_SEARCH) {<commit_msg>Fix for live updates in PanelView<commit_after>//import { searchGraph, searchPanel } from "../actions/panelView";

import Reflux from "reflux";
import Identifier from '../../model/Identifier';

import { setRootIdentifiers } from '../actions/application';

import Monitor from '../../model/Monitor';


export const PANEL_SEARCH = Symbol("PANEL_SEARCH");
export const GRAPH_SEARCH = Symbol("GRAPH_SEARCH");
export const DEFAULT_SEARCH = Symbol("DEFAULT_SEARCH");

var search = Reflux.createAction({
    asyncResult: true
});

export const searchGraph = function(identifier, params) {
    search(identifier, params, {context: GRAPH_SEARCH});
};

export const identifierSelect = function(identifier, columnIndex, params = {}) {
    search(identifier, params, {columnIndex, context: PANEL_SEARCH});
};

search.listen((identifier, params, options) => {
    identifier.search(params)
        .then(search.completed.bind(null, {identifier, params, ...options}))
        .catch(search.failed)
});

var storeUpdated = Reflux.createAction();

var storeDataUpdated = Reflux.createAction();

let updateMetadata = Reflux.createAction();

// TODO: This is for demo only
window.updateMetadata = updateMetadata;

export const globalStore = Reflux.createStore({
    getInitialState() {
        return {
            nodes: new Set(),
            edges: new Set()
        }
    },

    init() {
        this.state = this.getInitialState();
        this.listenTo(search.completed, this.onSearchCompleted);
        this.listenTo(updateMetadata, this.onMetadataUpdate);
        this.listenTo(setRootIdentifiers, this.setRootIdentifiers);

        this.monitor = new Monitor();
    },

    setRootIdentifiers(identifiers) {
        this.state = { nodes: new Set(identifiers), edges: new Set() };
        this._startMonitoring(identifiers);
        storeUpdated(this.state, {context: DEFAULT_SEARCH}, null);
    },

    onMetadataUpdate(identifier, metadata) {
        identifier.metadata = metadata;
        storeDataUpdated(this.state);
    },

    onSearchCompleted(options, result) {
        this.state = this._onSearchCompleted(result);
        storeUpdated(this.state, options, result);
    },

    _startMonitoring(identifiers) {
        this.monitor.listen(identifiers.map(i => i.name), i => {
            //Identifier.get(i.identifier);
            //console.log("monitoring", i);
        });
    },

    _onSearchCompleted({ identifiers, links }) {
        var { nodes, edges } = this.state;
        nodes = [...nodes];
        edges = [...edges];

        links = links.map((l) => {
            return {
                target: Identifier.get(l.target),
                source: Identifier.get(l.source),
                data: l
            }
        });

        nodes.push(...identifiers);
        edges.push(...links);

        this._startMonitoring(identifiers);

        return { nodes: new Set(nodes), edges: new Set(edges) };
    }

});

export const graphStore = Reflux.createStore({
    getInitialState() {
        return globalStore.state;
        //return {
        //    nodes: [],
        //    edges: []
        //}
    },

    init() {
        this.listenTo(storeUpdated, this.onStoreUpdated);
        this.listenTo(storeDataUpdated, this.onStoreUpdated);
    },

    onStoreUpdated(state, options, results) {
        this.trigger(state);
    }
});

export const panelStore = Reflux.createStore({
    getInitialState() {
        return {
            items: []
        }
    },

    init() {
        this.state = this.getInitialState();
        this.listenTo(storeUpdated, this.onStoreSearchUpdated);
        this.listenTo(storeDataUpdated, () => {
            this.trigger(this.state);
        });

    },

    onStoreSearchUpdated(state, options, results = null) {
        if (options.context === PANEL_SEARCH) {
{'fraction_non_alphanumeric': 0.13534034900759292, 'fraction_numerical': 0.0, 'mean_word_length': 2.5992329817833175, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 12, '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': '7550776', 'n_tokens_mistral': 2145, 'n_tokens_neox': 2079, 'n_words': 423}