<commit_before>'use strict'

utils = require 'utils'
assert = require 'assert'

module.exports = (File) ->
	renderStyles = do ->
		pending = false
		queue = []

		render = (arr) ->
			for style in arr
				style.render()
			for style in arr
				render style.children
			return

		renderAll = ->
			pending = false
			length = queue.length
			for arr in queue
				render arr
			assert.ok queue.length is length
			utils.clear queue
			return

		(arr) ->
			queue.push arr

			unless pending
				setImmediate renderAll
				pending = true
			return

	File.onBeforeRender (file) ->
		renderStyles file.styles
		return

	revertStyles = (arr) ->
		for style in arr
			style.revert()
		for style in arr
			revertStyles style.children
		return

	File.onBeforeRevert (file) ->
		revertStyles file.styles
		return

	File::_clone = do (_super = File::_clone) -> ->
		clone = _super.call @

		# styles
		for style, i in @styles
			clone.styles.push style.clone @, clone

		clone
<commit_msg>Style rendering race condition fixed<commit_after>'use strict'

utils = require 'utils'
assert = require 'assert'

module.exports = (File) ->
	renderStyles = do ->
		pending = false
		queue = []

		render = (arr) ->
			for style in arr
				unless style.isRendered
					style.render()
			for style in arr
				render style.children
			return

		renderAll = ->
			pending = false
			length = queue.length
			for arr in queue
				render arr
			assert.ok queue.length is length
			utils.clear queue
			return

		(arr) ->
			queue.push arr

			unless pending
				setImmediate renderAll
				pending = true
			return

	File.onBeforeRender (file) ->
		renderStyles file.styles
		return

	revertStyles = (arr) ->
		for style in arr
			style.revert()
		for style in arr
			revertStyles style.children
		return

	File.onBeforeRevert (file) ->
		revertStyles file.styles
		return

	File::_clone = do (_super = File::_clone) -> ->
		clone = _super.call @

		# styles
		for style, i in @styles
			clone.styles.push style.clone @, clone

		clone

{'fraction_non_alphanumeric': 0.09213147410358566, 'fraction_numerical': 0.0, 'mean_word_length': 2.6593806921675776, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, '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': '5586760', 'n_tokens_mistral': 774, 'n_tokens_neox': 638, 'n_words': 200}