--[[----------------------------------------------------------------------------

ADOBE CONFIDENTIAL
------------------
Copyright 2016 Adobe Systems Incorporated
All Rights Reserved.

NOTICE: All information contained herein is, and remain the property of
Adobe Systems Incorporated and its suppliers, if any. The intellectual and
technical concepts contained herein are proprietary to Adobe Systems
Incorporated and its suppliers and may be covered by U.S. and Foreign
Patents, patents in process, and are protected by trade secret or copyright
law.  Dissemination of this information or reproduction of this material is
strictly forbidden unless prior written permission is obtained from
Adobe Systems Incorporated.

----------------------------------------------------------------------------]]--

	-- RxLua
local Rx = require 'Rx'

--------------------------------------------------------------------------------

local Observable = Rx.Observable
local CompositeDisposable = Rx.CompositeDisposable

--==============================================================================

local DisposableObservable = Rx.Class 'WFRxDisposeOnUnsubscribeObservable' {

	Observable,
	
	_compositeDisposable = false,
		-- (CompositeDisposable)
	
	_source = false,
		-- (Observable)
	
	--------------------------------------------------------------------------------

	__init = function( self, source )
	
		self._compositeDisposable = CompositeDisposable()
		self._source = source
		
	end,
	
	--------------------------------------------------------------------------------

	_subscribe = function( self, observer )

		return CompositeDisposable( self._source:subscribe( observer ),
			self._compositeDisposable )

	end,
	
	--------------------------------------------------------------------------------

	addDisposable = function( self, disposable )
	
		self._compositeDisposable:add( disposable )
		
	end,
	
	--------------------------------------------------------------------------------

	removeDisposable = function( self, disposable )
	
		self._compositeDisposable:remove( disposable )
		
	end
	
}

--------------------------------------------------------------------------------

return function( self )

	return DisposableObservable( self )
	
end