dotJEM / angular-routing

Enhanced state based routing for Angular applications!
https://dotjem.github.io/angular-routing/
MIT License
75 stars 9 forks source link

Refactor StateParameter extraction #21

Open jeme opened 11 years ago

jeme commented 11 years ago

This is a thought for now, but we have some dupelicate code that extracts parameters from states it is however not 100% the same code, but similar enough to make for a single function doing so.

This is currently done in 3 places.

something in lines of:

    function extractStateParams(state, params?) {
        var currentState = $state.current,
            currentParams = (currentState && currentState.$params && currentState.$params.all),
            stateParams = {};

        forEach(state.route.params, (param, name) => {
            if (name in currentParams)
                stateParams[name] = currentParams[name];
        });

        return extend(stateParams, params || {});
    }