<commit_before>import 'package:redarx/src/request.dart';
import 'package:redarx/src/dispatcher.dart';
import 'package:redarx/src/model.dart';
import 'package:redarx/src/store.dart';

/**
 * type of method which provide a method to instantiate a new Command
 */
typedef Command<T> CommandBuilder<T extends AbstractModel>(dynamic value);


/**
 * Command Base class
 */
abstract class Command<G extends AbstractModel> {
  G exec(G model);
}

/**
 * listen to dispatcher's stream of actions and map them to commands, executed on the store
 */
class Commander {
  /**
   * commander config : RequestType » Commands mapping
   */
  CommanderConfig config;

  /**
   * store
   */
  Store<AbstractModel> store;

  /**
   * request dispatcher
   */
  Dispatcher dispatcher;

  /**
   *
   * @param CommanderConfig config
   * @param Store<AbstractModel> this.store
   * @param Dispatcher this.dispatcher
   */
  Commander(CommanderConfig this.config, Store<AbstractModel> this.store,
      Dispatcher this.dispatcher) {
    dispatcher.onRequest.listen((Request a) => exec(a));
  }

  /**
   * cancel last store command
   */
  cancel() => store.cancel();

  /**
   * update store with Command defined by Request
   */
  exec(Request a) {
    var handler = this.config.getHandler(a.actionType);
    try{
      store.update(handler(a.value));
    } catch (err){
      print('Commander.handle... No command defined for this Action ${a} \n $err');
    }
  }
}

/**
 * pair Action » CommandBuilders
 */<commit_msg>Refactoring : inject on requestStream in Commander ( not the whole dispatcher )<commit_after>import 'dart:async';

import 'package:redarx/src/model.dart';
import 'package:redarx/src/request.dart';
import 'package:redarx/src/store.dart';

/**
 * type of method which provide a method to instantiate a new Command
 */
typedef Command<T> CommandBuilder<T extends AbstractModel>(value);


/**
 * Command Base class
 */
abstract class Command<G extends AbstractModel> {
  G exec(G model);
}

/**
 * listen to dispatcher's stream of actions and map them to commands, executed on the store
 */
class Commander {
  /**
   * commander config : RequestType » Commands mapping
   */
  CommanderConfig config;

  /**
   * store
   */
  Store<AbstractModel> store;

  /**
   *
   * @param CommanderConfig config
   * @param Store<AbstractModel> this.store
   * @param Stream<Request> requestStream
   */
  Commander(CommanderConfig this.config, Store<AbstractModel> this.store,
      Stream<Request> requestStream) {
    requestStream.listen((Request a) => exec(a));
    store.apply();
  }

  /**
   * cancel last store command
   */
  cancel() => store.cancel();

  /**
   * update store with Command defined by Request
   */
  exec(Request a) {
    var handler = this.config.getHandler(a.actionType);
    try{
      store.update(handler(a.value));
    } catch (err){
      print('Commander.handle... No command defined for this Action ${a} \n $err');
    }
  }
}

/**
 * pair Action » CommandBuilders
 */
{'fraction_non_alphanumeric': 0.12954924874791318, 'fraction_numerical': 0.0, 'mean_word_length': 3.323232323232323, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 21, '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': '3267719', 'n_tokens_mistral': 920, 'n_tokens_neox': 899, 'n_words': 252}