 
 #if DEBUG
 //    actionSource.debug().subscribe().addDisposableTo(self.disposeBag)
-//    stateSource
-//      .filter { $0.mainWindows.values.count > 0 }
-//      .map { Array($0.mainWindows.values)[0].preview }
-//      .debug()
-//      .subscribe(onNext: { state in
-//      })
-//      .addDisposableTo(self.disposeBag)
+//    stateSource.debug().subscribe().addDisposableTo(self.disposeBag)
 #endif
   }
 

    // Preferences
    Observable
      .of(
        actionSource
          .mapOmittingNil { $0 as? PrefWindow.Action }
          .map { self.appStateActionPair(for: $0) }
          .reduce(by: PrefWindowReducer())
          .filter { $0.modified }
          .map { $0.state },
        actionSource
          .mapOmittingNil { $0 as? GeneralPref.Action }
          .map { self.appStateActionPair(for: $0) }
          .reduce(by: GeneralPrefReducer())
          .filter { $0.modified }
          .map { $0.state },
        actionSource
          .mapOmittingNil { $0 as? AppearancePref.Action }
          .map { self.appStateActionPair(for: $0) }
          .reduce(by: AppearancePrefReducer())
          .filter { $0.modified }
          .map { $0.state },
        actionSource
          .mapOmittingNil { $0 as? AdvancedPref.Action }
          .map { self.appStateActionPair(for: $0) }
          .reduce(by: AdvancedPrefReducer())
          .filter { $0.modified }
          .map { $0.state }
      )
      .merge()
      .apply(to: prefService.forPrefPanes)
      .subscribe(onNext: self.emitAppState)

    }
  }

  fileprivate func actionSourceForAppState<T>() -> Observable<StateActionPair<AppState, T>> {
    return self.actionEmitter.observable
      .mapOmittingNil { $0 as? T }
      .map { self.appStateActionPair(for: $0) }
  }

  fileprivate func actionSourceForMainWindow<T>() -> Observable<StateActionPair<UuidState<MainWindow.State>, T>> {
    return self.actionEmitter.observable
      .mapOmittingNil { $0 as? UuidAction<T> }
      .mapOmittingNil { self.mainWindowStateActionPair(for: $0) }
  }

  fileprivate func appStateActionPair<ActionType>(for action: ActionType) -> StateActionPair<AppState, ActionType> {
    return StateActionPair(state: self.appState, action: action, modified: false)
  }
