<commit_before>package net.jmeze.jredux;

import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicReference;

public class BaseStore<S> implements Store<S> {

    // all state objects (ie initialState and any state returned by the reducer) must be immutable
    // with immutable state objects we only need to synchronize access to the reference to the state

    // reducers must be pure functions - functions that return the exact same output for given inputs.
    // They should also be free of side-effects.

    // access/updates to subscribers must be thread safe, so use CopyOnWriteArrayList
    // listeners are often cited as a good use for CopyOnWriteArrayList.  Note any modifications of CopyOnWriteArrayList
    // are protected by a ReentrantLock in the implementation, we do not need to do

    private static final ThreadLocal<Boolean> isDispatching =
            new ThreadLocal<Boolean>() {
                @Override protected Boolean initialValue() {
                    return false;
                }
            };

    private final AtomicReference<S> currentState = new AtomicReference<S>();
    private final Reducer<S> reducer;
    private final List<Subscriber<S>> subscribers = new CopyOnWriteArrayList<Subscriber<S>>();

    public BaseStore(S initialState, Reducer<S> reducer) {
        isDispatching.set(false);
        currentState.set(initialState);
        this.reducer = reducer;
    }

    @Override
    public S getState() {
        return currentState.get();
    }

    @Override
    public void dispatch(Action action) {

        // if actions arrive on multiple threads, these threads may block on the synchronized section.
        // the order in which they wake and eventually pass through the synchronized section cannot be determined
        // which may have intended consequences: say we have current state = 1 and an action "add 10" followed by
        // "multiply by 10" - if the action order is switched the resulting state is different :(

        // therefore dispatch can only guarantee the order of actions called from the same thread - you
        // almost certainly want to be calling from the same thread anyway otherwise you'll probably encounter race
        // conditions.
<commit_msg>remove a stray piece of code<commit_after>package net.jmeze.jredux;

import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicReference;

public class BaseStore<S> implements Store<S> {

    // all state objects (ie initialState and any state returned by the reducer) must be immutable
    // with immutable state objects we only need to synchronize access to the reference to the state

    // reducers must be pure functions - functions that return the exact same output for given inputs.
    // They should also be free of side-effects.

    // access/updates to subscribers must be thread safe, so use CopyOnWriteArrayList
    // listeners are often cited as a good use for CopyOnWriteArrayList.  Note any modifications of CopyOnWriteArrayList
    // are protected by a ReentrantLock in the implementation, we do not need to do

    private static final ThreadLocal<Boolean> isDispatching =
            new ThreadLocal<Boolean>() {
                @Override protected Boolean initialValue() {
                    return false;
                }
            };

    private final AtomicReference<S> currentState = new AtomicReference<S>();
    private final Reducer<S> reducer;
    private final List<Subscriber<S>> subscribers = new CopyOnWriteArrayList<Subscriber<S>>();

    public BaseStore(S initialState, Reducer<S> reducer) {
        currentState.set(initialState);
        this.reducer = reducer;
    }

    @Override
    public S getState() {
        return currentState.get();
    }

    @Override
    public void dispatch(Action action) {

        // if actions arrive on multiple threads, these threads may block on the synchronized section.
        // the order in which they wake and eventually pass through the synchronized section cannot be determined
        // which may have intended consequences: say we have current state = 1 and an action "add 10" followed by
        // "multiply by 10" - if the action order is switched the resulting state is different :(

        // therefore dispatch can only guarantee the order of actions called from the same thread - you
        // almost certainly want to be calling from the same thread anyway otherwise you'll probably encounter race
        // conditions.

{'fraction_non_alphanumeric': 0.06235011990407674, 'fraction_numerical': 0.0021800741225201656, 'mean_word_length': 2.9483648881239244, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, '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': '4033777', 'n_tokens_mistral': 1121, 'n_tokens_neox': 1064, 'n_words': 502}