     // 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 }
-      )
+        self.actionSourceForAppState()
+            .reduce(by: PrefWindowReducer())
+            .filterMapPair(),
+        self.actionSourceForAppState()
+            .reduce(by: GeneralPrefReducer())
+            .filterMapPair(),
+        self.actionSourceForAppState()
+            .reduce(by: AppearancePrefReducer())
+            .filterMapPair(),
+        self.actionSourceForAppState()
+            .reduce(by: AdvancedPrefReducer())
+            .filterMapPair()
+        )
       .merge()
       .apply(to: prefService.forPrefPanes)
       .subscribe(onNext: self.emitAppState)


#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)
#endif
  }



extension Observable {

  fileprivate func reduce<T:Reducer>(by reducer: T) -> Observable<Element> where T.Pair == Element {
    return reducer.reduce(self)
  }

  fileprivate func apply<S:Service>(to service: S) -> Observable<Element> where S.Pair == Element {
    return self.do(onNext: service.apply)
