let Diode  = require('diode')
let signal = require('./signal')

const INACTIVE = 'INACTIVE'
const PARTIAL  = 'PARTIAL'
const ABORTED  = 'ABORTED'
const COMPLETE = 'COMPLETE'

function Transaction(action, params) {
  Diode(this)

  this.action = action
  this.params = params

  this.body   = null
  this.error  = null
  this.state  = INACTIVE
}

Transaction.prototype = {

  constructor: Transaction,

  run() {
    let body = this.action.apply(this, this.params)

    return signal(this.resolve.bind(this), this.reject.bind(this), body)
  },

  resolve(body, done) {
    this.body  = body

    this.state = this.isFinished() || done ? COMPLETE : PARTIAL

    this.publish()
  },

  reject(error) {
    this.error = error
    this.state = ABORTED

    this.publish()
  },

  isInactive() {
    return this.state === INACTIVE
  },

  isValid() {
    return this.state !== ABORTED
  },

  isFinished() {
    return this.state === COMPLETE
  }

}

module.exports = Transaction

@@ -774,17 +774,14 @@
   is
-Inactive(
+(state
 ) %7B%0A
@@ -806,24 +806,93 @@
 ate === 
-INACTIVE
+state%0A  %7D,%0A%0A  isInactive() %7B%0A    return this.is(INACTIVE) %7C%7C this.is(ABORTED)
 %0A  %7D,%0A%0A 
@@ -924,25 +924,29 @@
 his.
-state !== ABORTED
+is(ABORTED) === false
 %0A  %7D
@@ -985,26 +985,19 @@
 his.
-state === 
+is(
 COMPLETE
 %0A  %7D
@@ -992,16 +992,17 @@
 COMPLETE
+)
 %0A  %7D%0A%0A%7D%0A

Add is method