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

ADOBE CONFIDENTIAL
------------------
Copyright 2013 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.

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

local KSLifoLater = require 'KSLifoLater'
local KSReactive = require 'KSReactive'

local kMainThreadManagedEpochStack = KSLifoLater.makeEpochStack()
local kScrollingStoppedEpochStack = KSLifoLater.makeEpochStack()

local kTriggerB = KSReactive.variableB( false )
local kTriggerScrollingStoppedB = KSReactive.variableB( false )

local LrmEpochModel = {}


function LrmEpochModel.makeEpochModel( )
	return {
		epochStack = kMainThreadManagedEpochStack,
		
		valueB = KSReactive.tableB {
			primaryTrigger = kTriggerB,
			scrollingStoppedTrigger = kTriggerScrollingStoppedB,
		},
		
		events = {
			signal = function()
				kTriggerB:set( false )
				kMainThreadManagedEpochStack:signalEpochBoundary( true )
			end,
			scrollingStopped = function()
				kTriggerScrollingStoppedB:set( false )
				kScrollingStoppedEpochStack:signalEpochBoundary( true )
			end,
		},
	}
end

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

LrmEpochModel.currentScrollingStoppedEpochB = function()
	kTriggerScrollingStoppedB:set( true )
	return kScrollingStoppedEpochStack:getEpochB()
			:mapB( function( value )
				return value
			end )
	end

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

LrmEpochModel.currentEpochB = function()
	kTriggerB:set( true )
	return kMainThreadManagedEpochStack:getEpochB()
			:mapB( function( value )
				return value
			end )
	end

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

return LrmEpochModel
