<commit_before>import { Store }            from 'airflux';
import Firebase             from 'firebase';

import AuthStore            from './AuthStore';
import * as Actions         from './BoardActions';

class BoardStore extends Store {

    state = {
        widgets : [],
        authStoreState : '',
        zoom : 1
    };

    constructor() {
        super();

        this.listenTo( AuthStore, this._onAuthSuccess.bind( this ) );

        Actions.setSize.listen( this._setSize.bind( this ) );
        Actions.addWidget.listen( this._addWidget.bind( this ) );
        Actions.removeWidget.listen( this._removeWidget.bind( this ) );
        Actions.clearBoard.listen( this._clearBoard.bind( this ) );
        Actions.setZoom.listen( this._setZoom.bind(this ) );
    }

    get size() { return this.state.size; }

    get zoom() { return this.state.zoom || 1; }

    destroy() {
        this.boardSizeRef.off();
        this.widgetsRef.off();
        this.latestIndexRef.off();
    }

    _setZoom( zoom ) {
        this.state.zoom = zoom;
    }

    // FIXME : use promise
    getLatestIndex( callback ) {
        this.latestIndexRef.transaction( latestIndex => ( latestIndex || 0 ) + 1, callback );
    }

    _onAuthSuccess( authStoreState ) {
        const { firebaseUrl , boardKey } = authStoreState.appConfig;
        this.authStoreState = authStoreState;
        //this.boardSizeRef = new Firebase( `${firebaseUrl}/boards/${boardKey}/size` );
        //this.widgetsRef = new Firebase( `${firebaseUrl}/boards/${boardKey}/widget` );
        //this.latestIndexRef = new Firebase( `${firebaseUrl}/boards/${boardKey}/latestWidgetIndex` );

        this.boardSizeRef = new Firebase( `${firebaseUrl}/boards/${boardKey}/size` );
        this.widgetsRef = new Firebase( `${firebaseUrl}/widgets/${boardKey}` );
        this.latestIndexRef = new Firebase( `${firebaseUrl}/boards/${boardKey}/latestWidgetIndex` );

        this.widgetsRef.on( 'child_added', this._onAddWidget.bind( this ) );
        this.widgetsRef.on( 'child_removed', this._onRemoveWidget.bind( this ) );
        this.boardSizeRef.on( 'value', this._onNewSize.bind( this ) );
    }

    _onAddWidget( dataSnapshot ) {
        let { widgets } = this.state;
        widgets.push( { key : dataSnapshot.key(), val : dataSnapshot.val() } );<commit_msg>initialize list of empty widget<commit_after>import { Store }            from 'airflux';
import Firebase             from 'firebase';

import AuthStore            from './AuthStore';
import * as Actions         from './BoardActions';

class BoardStore extends Store {

    state = {
        widgets : [],
        authStoreState : '',
        zoom : 1
    };

    constructor() {
        super();

        this.listenTo( AuthStore, this._onAuthSuccess.bind( this ) );

        Actions.setSize.listen( this._setSize.bind( this ) );
        Actions.addWidget.listen( this._addWidget.bind( this ) );
        Actions.removeWidget.listen( this._removeWidget.bind( this ) );
        Actions.clearBoard.listen( this._clearBoard.bind( this ) );
        Actions.setZoom.listen( this._setZoom.bind(this ) );
    }

    get size() { return this.state.size; }

    get zoom() { return this.state.zoom || 1; }

    destroy() {
        this.boardSizeRef.off();
        this.widgetsRef.off();
        this.latestIndexRef.off();
    }

    _setZoom( zoom ) {
        this.state.zoom = zoom;
    }

    // FIXME : use promise
    getLatestIndex( callback ) {
        this.latestIndexRef.transaction( latestIndex => ( latestIndex || 0 ) + 1, callback );
    }

    _onAuthSuccess( authStoreState ) {
        const { firebaseUrl , boardKey } = authStoreState.appConfig;
        this.authStoreState = authStoreState;

        this.boardSizeRef = new Firebase( `${firebaseUrl}/boards/${boardKey}/size` );
        this.widgetsRef = new Firebase( `${firebaseUrl}/widgets/${boardKey}` );
        this.latestIndexRef = new Firebase( `${firebaseUrl}/boards/${boardKey}/latestWidgetIndex` );

        this.widgetsRef.off();
        this.boardSizeRef.off();
        this.state.widgets = [];


        this.widgetsRef.on( 'child_added', this._onAddWidget.bind( this ) );
        this.widgetsRef.on( 'child_removed', this._onRemoveWidget.bind( this ) );
        this.boardSizeRef.on( 'value', this._onNewSize.bind( this ) );
    }

    _onAddWidget( dataSnapshot ) {
        let { widgets } = this.state;
        widgets.push( { key : dataSnapshot.key(), val : dataSnapshot.val() } );
{'fraction_non_alphanumeric': 0.1405550581915846, 'fraction_numerical': 0.0017905102954341987, 'mean_word_length': 2.5078492935635794, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '79994', 'n_tokens_mistral': 1347, 'n_tokens_neox': 1303, 'n_words': 251}