'use strict';

import * as Kefir from 'kefir';

window.Kefir = Kefir;

/**
 * @class Subject
 */
export default class Subject {

  /**
   * Subject for `Component` ui events & `Action` publish events.
   *
   * @returns {Kefir.Stream}
   */
  static stream() {
    return Subject.create(Kefir.Stream);
  }

  /**
   * Subject for `Store` data property.
   * Even when starting to subscribe to retained latest value will be published.
   *
   * @param {*} initialValue
   * @returns {Kefir.Property}
   */
  static property(initialValue) {
    return Subject.create(Kefir.Property, initialValue);
  }

  /**
   * @param {Kefir.Stream|Kefir.Property} BaseClass
   * @param {*} [initialValue]
   * @returns {Kefir.Observable}
   */
  static create(BaseClass, initialValue) {

    function Subject() {
      Subject._emitValue.apply(Subject, arguments);
    }

    for (let key in BaseClass.prototype) {
      Subject[key] = BaseClass.prototype[key];
    }

    Subject.push  = Subject._emitValue;
    Subject.error = Subject._emitError;
    Subject.end   = Subject._emitEnd;

    BaseClass.call(Subject, initialValue);

    return Subject;
  }

  //static createFromRx(BaseClass, initialValue) {
  //
  //  function Subject() {
  //    Subject.onNext.apply(Subject, arguments);
  //  }
  //
  //  for (let key in BaseClass.prototype) {
  //    Subject[key] = BaseClass.prototype[key];
  //  }
  //
  //  // aliases
  //  Subject.push  = Subject.onNext;
  //  Subject.error = Subject.onError;
  //  Subject.end   = Subject.onEnd;
  //
  //  // construct `Rx.Subject` as Subject
  //  BaseClass.call(Subject, initialValue);
  //
  //  return Subject;
  //}
}

@@ -45,31 +45,8 @@
 ';%0A%0A
-window.Kefir = Kefir;%0A%0A
 /**%0A
@@ -600,29 +600,18 @@
 fir.
-Stream%7CKefir.Property
+Observable
 %7D Ba
@@ -634,17 +634,16 @@
 ram %7B*%7D 
-%5B
 initialV
@@ -646,17 +646,16 @@
 ialValue
-%5D
 %0A   * @r
@@ -735,33 +735,34 @@
 %7B%0A%0A    function 
-S
+_s
 ubject() %7B%0A     
@@ -758,25 +758,26 @@
 t() %7B%0A      
-S
+_s
 ubject._emit
@@ -784,25 +784,26 @@
 Value.apply(
-S
+_s
 ubject, argu
@@ -862,25 +862,26 @@
 pe) %7B%0A      
-S
+_s
 ubject%5Bkey%5D 
@@ -915,25 +915,26 @@
 %0A    %7D%0A%0A    
-S
+_s
 ubject.push 
@@ -932,25 +932,26 @@
 ect.push  = 
-S
+_s
 ubject._emit
@@ -957,25 +957,26 @@
 tValue;%0A    
-S
+_s
 ubject.error
@@ -974,25 +974,26 @@
 ect.error = 
-S
+_s
 ubject._emit
@@ -999,25 +999,26 @@
 tError;%0A    
-S
+_s
 ubject.end  
@@ -1016,25 +1016,26 @@
 ect.end   = 
-S
+_s
 ubject._emit
@@ -1063,544 +1063,185 @@
 all(
-S
+_s
 ubject
-, initialValue);%0A%0A    return Subject;%0A  %7D%0A%0A  //static createFromRx(BaseClass, initialValue) %7B%0A  //%0A  //  function Subject(
+);%0A%0A    if (initialValue !== undefined
 ) %7B%0A  
-//
     
-S
+_s
 ubject.
-onNext.apply(Subject, arguments);%0A  //  %7D%0A  //%0A  //  for (let key in BaseClass.prototype) %7B%0A  //    Subject%5Bkey%5D = BaseClass.prototype%5Bkey%5D;%0A  //  %7D%0A  //%0A  //  // aliases%0A  //  Subject.push  = Subject.onNext;%0A  //  Subject.error = Subject.onError;%0A  //  Subject.end   = Subject.onEnd;%0A  //%0A  //  // construct %60Rx.Subject%60 as Subject%0A  //  BaseClass.call(Subject, initialValue);%0A  //
+_active = true;%0A      _subject._currentEvent = %7Btype : 'value', value : initialValue, current : true%7D;%0A    %7D%0A
 %0A  
-//
   re
@@ -1241,25 +1241,26 @@
 %0A    return 
-S
+_s
 ubject;%0A  //
@@ -1261,10 +1261,8 @@
 ;%0A  
-//
 %7D%0A%7D%0A

fix subject.property