<commit_before>import {store_handler} from './stores'
import {patch, attributes} from 'incremental-dom'
import {REMOVED} from './stores'
import {add_style} from './style'

export {REMOVED, add_style}

function set_global_state(fun) {
    attributes.__stores = store_handler(fun)
}

function clean_global_state(old) {
    // probably we don't need to clean attributes.__stores
}

export default function init(element, template) {
    function render() {
        let obj = set_global_state(render)
        try {
            patch(element, template)
        } catch(e) {
            console.error("Render error", e)
        }
        clean_global_state(obj)
    }
    render()
    return render
}<commit_msg>Use `requestAnimationFrame` instead of redrawing immediately<commit_after>import {store_handler} from './stores'
import {patch, attributes} from 'incremental-dom'
import {REMOVED} from './stores'
import {add_style} from './style'

export {REMOVED, add_style}

function set_global_state(fun) {
    attributes.__stores = store_handler(fun)
}

function clean_global_state(old) {
    // probably we don't need to clean attributes.__stores
}

export default function init(element, template) {
    let queued = false;
    function rerender() {
        if(!queued) {
            queued = true;
            window.requestAnimationFrame(render)
        }
    }
    function render() {
        queued = false;
        let obj = set_global_state(rerender)
        try {
            patch(element, template)
        } catch(e) {
            console.error("Render error", e)
        }
        clean_global_state(obj)
    }
    render() // Immediate render works better with hot reload
    return rerender
}
{'fraction_non_alphanumeric': 0.10365135453474676, 'fraction_numerical': 0.0, 'mean_word_length': 2.870159453302961, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6501922', 'n_tokens_mistral': 505, 'n_tokens_neox': 496, 'n_words': 131}