<commit_before>###
Copyright (c) 2012 [DeftJS Framework Contributors](http://deftjs.org)
Open source under the [MIT License](http://en.wikipedia.org/wiki/MIT_License).
###

# @private
Ext.define( 'Deft.mvc.Observer',

	host: null
	target: null
	events: null
	listeners: []

	###

	target = "propName"
	events = // is object
		event1: "handler1" // is string or function
		event2: "handler2 // is string or function"

	target = "propName2.prop"
	events = // is object
		event3: // is object
			fn: "handler3"
			scope: @
			options:
				option1: "value"
		event4: [ "handler4", "handler5" ] //is array

	if (map.indexOf('.') > -1) {
    map = map.split('.', 2);
    var v = n[map[0]][map[1]];
	} else {
	    var v = n[map];
	}
	###
	constructor: ( config ) ->
		Ext.apply( @, config )

		if @host[ @target ] and @host[ @target ]?.isObservable
			for eventName, listener of @events
				Deft.Logger.log( "Creating observer on '#{ @target }' for event '#{ eventName }'." )
				console.log( "Creating observer on '#{ @target }' for event '#{ eventName }'." )
				if Ext.isFunction( listener )
					@host[ @target ].on( eventName, listener, @host )
				else if Ext.isFunction( @host[ listener ] )
					@host[ @target ].on( eventName, @host[ listener ], @host )
				else
					Deft.Logger.warn( "Could not create observer on '#{ @target }' for event '#{ eventName }'." )
		else
			Deft.Logger.warn( "Could not create observers on '#{ @target }' because '#{ @target }' is not an Ext.util.Observable" )
			console.log( "Could not create observers on '#{ @target }' because '#{ @target }' is not an Ext.util.Observable" )

		return @

	destroy: ->
		if @host[ @target ] and @host[ @target ]?.isObservable
			for eventName, listener of @events
				Deft.Logger.log( "Removing observer on '#{ @target }' for event '#{ eventName }'." )
				console.log( "Removing observer on '#{ @target }' for event '#{ eventName }'." )
				if Ext.isFunction( listener )
					@host[ @target ].un( eventName, listener, @host )
				else if Ext.isFunction( @host[ listener ] )
					@host[ @target ].un( eventName, @host[ listener ], @host )

		delete @host
		return
)<commit_msg>Refactor Observer to maintain an array of listener references and use this for listener removal, rather than rely on iterating back over the passed configuration data.<commit_after>###
Copyright (c) 2012 [DeftJS Framework Contributors](http://deftjs.org)
Open source under the [MIT License](http://en.wikipedia.org/wiki/MIT_License).
###

# @private
Ext.define( 'Deft.mvc.Observer',

	host: null
	target: null
	events: null
	listeners: []

	###

	target = "propName"
	events = // is object
		event1: "handler1" // is string or function
		event2: "handler2 // is string or function"

	target = "propName2.prop"
	events = // is object
		event3: // is object
			fn: "handler3"
			scope: @
			options:
				option1: "value"
		event4: [ "handler4", "handler5" ] //is array

	if (map.indexOf('.') > -1) {
    map = map.split('.', 2);
    var v = n[map[0]][map[1]];
	} else {
	    var v = n[map];
	}
	###
	constructor: ( config ) ->
		Ext.apply( @, config )

		if @host[ @target ] and @host[ @target ]?.isObservable
			for eventName, fn of @events
				Deft.Logger.log( "Creating observer on '#{ @target }' for event '#{ eventName }'." )
				console.log( "Creating observer on '#{ @target }' for event '#{ eventName }'." )

				listenerData = null

				if Ext.isFunction( fn )
					listenerData = { target: @host[ @target ], event: eventName, fn: fn, scope: @host }
				else if Ext.isFunction( @host[ fn ] )
					listenerData = { target: @host[ @target ], event: eventName, fn: @host[ fn ], scope: @host }

				if listenerData
					listenerData.target.on( listenerData.event, listenerData.fn, listenerData.scope )
					@listeners.push( listenerData )
				else
					Deft.Logger.warn( "Could not create observer on '#{ @target }' for event '#{ eventName }'." )

		else
			Deft.Logger.warn( "Could not create observers on '#{ @target }' because '#{ @target }' is not an Ext.util.Observable" )
			console.log( "Could not create observers on '#{ @target }' because '#{ @target }' is not an Ext.util.Observable" )

		return @

	destroy: ->
		for listenerData in @listeners
			listenerData.target.un( listenerData.event, listenerData.fn, listenerData.scope )
		@listeners = []
		return
)
{'fraction_non_alphanumeric': 0.15987025023169602, 'fraction_numerical': 0.008804448563484708, 'mean_word_length': 3.2827380952380953, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4105765', 'n_tokens_mistral': 1615, 'n_tokens_neox': 1417, 'n_words': 435}