<commit_before>Store = require '../libs/flux/store/Store'

{ActionTypes} = require '../constants/AppConstants'

class AccountStore extends Store

    ###
        Initialization.
        Defines private variables here.
    ###

    # Creates an OrderedMap of accounts
    _accounts = Immutable.Sequence window.accounts

        # sort first
        .sort (mb1, mb2) ->
            if mb1.label > mb2.label then return 1
            else if mb1.label < mb2.label then return -1
            else return 0

        # sets account ID as index
        .mapKeys (_, account) -> return account.id

        # makes account object an immutable Map
        .map (account) ->

            account.mailboxes = Immutable.Sequence(account.mailboxes)

                # sets mailbox ID as index
                .mapKeys (_, mailbox) -> mailbox.id

                # makes mailbox object an immutable Map
                .map (mailbox) -> Immutable.Map mailbox
                .toOrderedMap()

            return Immutable.Map account


        .toOrderedMap()

    _selectedAccount = null
    _newAccountWaiting = false
    _newAccountError = null

    ###
        Defines here the action handlers.
    ###
    __bindHandlers: (handle) ->

        handle ActionTypes.ADD_ACCOUNT, (account) ->
            account = Immutable.Map account
            _accounts = _accounts.set account.get('id'), account
            @emit 'change'

        handle ActionTypes.SELECT_ACCOUNT, (accountID) ->
            _selectedAccount = _accounts.get(accountID) or null
            @emit 'change'

        handle ActionTypes.NEW_ACCOUNT_WAITING, (payload) -><commit_msg>Fixed: mailboxes were not recursively immutables<commit_after>Store = require '../libs/flux/store/Store'

{ActionTypes} = require '../constants/AppConstants'

class AccountStore extends Store

    ###
        Initialization.
        Defines private variables here.
    ###

    # Recursively creates Immutable OrderedMap of mailboxes
    createImmutableMailboxes = (children) ->
        Immutable.Sequence children
            .mapKeys (_, mailbox) -> mailbox.id
            .map (mailbox) ->
                mailbox.children = createImmutableMailboxes mailbox.children
                return Immutable.Map mailbox
            .toOrderedMap()

    # Creates an OrderedMap of accounts
    _accounts = Immutable.Sequence window.accounts

        # sort first
        .sort (mb1, mb2) ->
            if mb1.label > mb2.label then return 1
            else if mb1.label < mb2.label then return -1
            else return 0

        # sets account ID as index
        .mapKeys (_, account) -> return account.id

        # makes account object an immutable Map
        .map (account) ->
            account.mailboxes = createImmutableMailboxes account.mailboxes
            return Immutable.Map account

        .toOrderedMap()

    _selectedAccount = null
    _newAccountWaiting = false
    _newAccountError = null


    ###
        Defines here the action handlers.
    ###
    __bindHandlers: (handle) ->

        handle ActionTypes.ADD_ACCOUNT, (account) ->
            account = Immutable.Map account
            _accounts = _accounts.set account.get('id'), account
            @emit 'change'

        handle ActionTypes.SELECT_ACCOUNT, (accountID) ->
            _selectedAccount = _accounts.get(accountID) or null
            @emit 'change'

        handle ActionTypes.NEW_ACCOUNT_WAITING, (payload) ->
{'fraction_non_alphanumeric': 0.08432683919744112, 'fraction_numerical': 0.005234079674323932, 'mean_word_length': 1.991304347826087, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 24, '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': '4424279', 'n_tokens_mistral': 941, 'n_tokens_neox': 896, 'n_words': 255}