Skip to content

Removal of attributes from queryparams #2

Description

@coderberry

I found that when I removed fields from the params hash which is used to generate the QueryParameters object, it doesn't remove it from the URL. Here's what I had to do to resolve this:

/**
 * Returns the query parameters and actual contexts given
 * a handler name and list of contexts (the arguments to
 * transitionTo and generate). Returns an object with two
 * properties:
 * - queryParams: The query params object for the given arguments
 * - contexts: The contexts argument minus an eventual QueryParameters object.
 * - args: The full argument array for generate / transitionTo
 *          (handler name and contexts without query params).
 */
var queryPartition = function(router, handlerName, contexts) {
    var queryParams = {},
        currentHandlerInfos = router.currentHandlerInfos || [],
        overrideParams, handlers,
        matchPoint;

    // Detect a QueryParameters object and shift it off the parameters array
    if (contexts[0] && contexts[0] instanceof Ember.Router.QueryParameters) {
        var paramsObject = contexts.shift();
        overrideParams = paramsObject.getProperties(keys(paramsObject));
    }

    // Get the query parameters that should be maintained
    if (!router.hasRoute(handlerName)) {
        handlerName += '.index';
    }

    handlers = router.recognizer.handlersFor(handlerName);
    matchPoint = getMatchPoint(router, handlers, contexts);

    for (var i = 0, l = currentHandlerInfos.length; i < l, i < matchPoint; i++) {
        var handlerObj = currentHandlerInfos[i],
            handler = handlerObj.handler;

        // Merge with existing query params
        if (handler.currentQueryParams) {
            merge(queryParams, handler.currentQueryParams);
        }
    }

    // Overridden
    queryParams = overrideParams;

    // if (overrideParams) {
    //  // Merge the query object parameters into
    //  // the params.
    //  merge(queryParams, overrideParams);
    // }

    // // Clean out any value that is falsy
    // keys(queryParams).forEach(function(key) {
    //  if (!queryParams[key]) {
    //      delete queryParams[key];
    //  }
    // });

    return {
        contexts: contexts,
        queryParams: queryParams,
        args: [handlerName].concat(contexts)
    };
};

I don't want to mess up functionality, but I can't understand why the original code was there (see commented out sections).

Thanks!

Eric

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions