<commit_before>import * as myra from 'myra'
import * as router from 'myra-router'
import RouteComponent from './route-component'


/**
 * State
 */
type State = {
    routeCtx: router.RouteContext
}
const init = {} as State


/**
 * Updates
 */
const onLocationUpdate = (state: State, ctx: router.RouteContext) =>
    myra.evolve(state, x => x.routeCtx = ctx)

/**
 * Component
 */
export default myra.defineComponent({
    // The name of the component. Used for debugging purposes.
    name: 'LocationComponent',

    // Init takes either an initial model or a tuple of an initial model 
    // and one or more tasks to execute when the component is initialized.
    init: {
        state: init,
        effects: [router.addListener(onLocationUpdate)]
    },

    // The view function is called after update. 
    view: ctx =>
        <section>
            <h2>Router examples</h2>

            {ctx.state.routeCtx.matchAny({
                'test1': <p>Route to '/test1'.</p>,
                'test1/:param': (params: any) => <RouteComponent {...params} />
            }, <nothing />)}

            {ctx.state.routeCtx.match('test1/:param') ?
                <p>Location '/test2/:param' matched.</p> : <nothing />}

            <ul class="list-group">
                <li class="list-group-item">
                    <a href="" onclick={(ev: Event) => { ev.preventDefault(), ctx.invoke(router.routeTo('/test1')) } }>
                        Update location to '/test1'
                </a>
                </li>
                <li class="list-group-item">
                    <a href="" onclick={(ev: Event) => { ev.preventDefault(), ctx.invoke(router.routeTo('/test1/test2')) } }>
                        Update location to '/test1/test2'
                </a>
                </li><commit_msg>Change name of function<commit_after>import * as myra from 'myra'
import * as router from 'myra-router'
import RouteComponent from './route-component'


/**
 * State
 */
type State = {
    routeCtx: router.RouteContext
}
const init = {} as State


/**
 * Updates
 */
const onRoute = (state: State, ctx: router.RouteContext) =>
    myra.evolve(state, x => x.routeCtx = ctx)

/**
 * Component
 */
export default myra.defineComponent({
    // The name of the component. Used for debugging purposes.
    name: 'LocationComponent',

    // Init takes either an initial model or a tuple of an initial model 
    // and one or more tasks to execute when the component is initialized.
    init: {
        state: init,
        effects: [router.addListener(onRoute)]
    },

    // The view function is called after update. 
    view: ctx =>
        <section>
            <h2>Router examples</h2>

            {ctx.state.routeCtx.matchAny({
                'test1': <p>Route to '/test1'.</p>,
                'test1/:param': (params: any) => <RouteComponent {...params} />
            }, <nothing />)}

            {ctx.state.routeCtx.match('test1/:param') ?
                <p>Location '/test2/:param' matched.</p> : <nothing />}

            <ul class="list-group">
                <li class="list-group-item">
                    <a href="" onclick={(ev: Event) => { ev.preventDefault(), ctx.invoke(router.routeTo('/test1')) } }>
                        Update location to '/test1'
                </a>
                </li>
                <li class="list-group-item">
                    <a href="" onclick={(ev: Event) => { ev.preventDefault(), ctx.invoke(router.routeTo('/test1/test2')) } }>
                        Update location to '/test1/test2'
                </a>
                </li>
{'fraction_non_alphanumeric': 0.1483547127718907, 'fraction_numerical': 0.007250418293363078, 'mean_word_length': 1.8696, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 53, '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': '668333', 'n_tokens_mistral': 1043, 'n_tokens_neox': 1010, 'n_words': 276}