Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat(Location): add search() method which returns an Object #4905

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

NathanWalker
Copy link
Contributor

The utility function tryDecodeURIComponent may be better placed in a different file. This uses the same strategy and implementation found in Angular 1.x. Lemme know if any refactoring or moving around is needed.

closes #4824

@gkalpak
Copy link
Member

gkalpak commented Oct 26, 2015

Since the return value of location.search() is an object, I think care should be taken not to allow modifying the returned object.
(Not sure what the best approach would be though.)

@flyingmutant
Copy link

Shouldn't RouteParams also do the replace(/\+/g,'%20') + decodeURIComponent magic?

@NathanWalker
Copy link
Contributor Author

@flyingmutant Seems like it should. Hopefully a core team member can comment on that.
It is likely that the tryDecodeURIComponent utility function I added might be repurposed in the facade where other utility methods are and could be used forRouteParams as well. I can refactor that once I receive more direction.

@NathanWalker
Copy link
Contributor Author

@gkalpak I agree with you on making the returned Object immutable. I'll look into this.

@mhevery
Copy link
Contributor

mhevery commented Oct 27, 2015

@NathanWalker Your error means that there is no decodeURIComponent function in Dart. This is a case where Dart API is different then JS API. The way to solve it is that you have to create a decode.js and decode.dart where you create a function called decodeURIComponent and export it.

In JS case you simply rexport the function as is. In dart case you have to call https://api.dartlang.org/1.12.2/dart-core/Uri/decodeComponent.html

@NathanWalker
Copy link
Contributor Author

Thanks @mhevery , that's exactly what I needed to know. I updated the PR, squashed the commits and believe I have it solved now.

@btford
Copy link
Contributor

btford commented Oct 27, 2015

Not totally sure how I feel about this– I don't want applications injecting and and using search params. They should use RouteParams instead.

But the work on encoding/decoding params is much needed. Either way, this is some solid work, @NathanWalker. Please give me a bit to think about how best to proceed.

@mhevery – please check with me next time before marking tasks as community help so that we can be sure that the design is right. It's frustrating for developers to put a bunch of work into something that isn't conceptually quite right.

@NathanWalker NathanWalker force-pushed the location-search-method branch from 0136d15 to dc671ae Compare October 27, 2015 09:09
@NathanWalker
Copy link
Contributor Author

@btford I'm ok with using RouteParams if they will contain all search query params. However, in Angular 1.x using $routeParams did not work that way. It only included keys that came from the route configuration like :id, etc.. and did not have anything else like other random params in the query.

If RouteParams still behaves that way in Angular 2, then we would still want location.search() here like we all had in 1.x. This way if a component or app is not using routing at all, it could still easily access the params on the url.

@btford
Copy link
Contributor

btford commented Oct 27, 2015

Yep, Angular 2 has a different model. Component all the things!

On Tue, Oct 27, 2015 at 9:12 AM Nathan Walker [email protected]
wrote:

@btford https://github.com/btford I'm ok with using RouteParams if they
will contain all search query params. However, in Angular 1.x using
$routeParams did not work that way. It only included keys that came
from the route configuration like :id, etc.. and did not have anything
else like other random params in the query.

If RouteParams still behaves that way in Angular 2, then we would still
want location.search() here like we all had in 1.x.


Reply to this email directly or view it on GitHub
#4905 (comment).

@NathanWalker
Copy link
Contributor Author

If we can inject RouteParams without including the router package then we
would be good to go. But if RouteParams is only available by including the
router package in an end users application then we would still need this.

Basically we need an easy way to grab all query params at any time whether
the app is using the router or not is the thing.

On Tue, Oct 27, 2015 at 2:18 AM Brian Ford [email protected] wrote:

Yep, Angular 2 has a different model. Component all the things!

On Tue, Oct 27, 2015 at 9:12 AM Nathan Walker [email protected]
wrote:

@btford https://github.com/btford I'm ok with using RouteParams if
they
will contain all search query params. However, in Angular 1.x using
$routeParams did not work that way. It only included keys that came
from the route configuration like :id, etc.. and did not have anything
else like other random params in the query.

If RouteParams still behaves that way in Angular 2, then we would still
want location.search() here like we all had in 1.x.


Reply to this email directly or view it on GitHub
#4905 (comment).


Reply to this email directly or view it on GitHub
#4905 (comment).

@btford
Copy link
Contributor

btford commented Oct 27, 2015

Right now Location is only available in angular2/router. I think it's reasonable to break it out into its own package later so you can use it without the router. But that's a separate concern. It's worth opening a separate issue about it, but there are many higher priority items so it's not likely that I'll have a change to take a look at that any time soon.

But yes, I do want to eventually support use of Location without the router.

@gkalpak
Copy link
Member

gkalpak commented Oct 27, 2015

Do RouteParams really include the query params ? That would be...unintuitive.
In any case, getting access to the query params should be independent of the ngComponentRouter imo.

Unless there is some reason (I am missing right now), that ng2 apps should not rely on/access the URL's query params. (If that's the case, prepare yourself for looots of complaining 😃)

@mhevery mhevery modified the milestones: beta.02, beta.01 Jan 25, 2016
@tagazok
Copy link

tagazok commented Jan 27, 2016

Hi. I looked in the source code and it seems that the search() function is not equivalent to what we had in Angular1. Is there any plan to also support setter for query params?
It's actually very useful when dealing with search/filter parameters where we don't want to reload the page but we still want to be able to copy/past the url with the page state :)

@NathanWalker
Copy link
Contributor Author

@tagazok Thank you for pointing that out! I'll see about making the changes to this PR to support that.

@petebacondarwin petebacondarwin added feature Issue that requests a new feature comp: router and removed comp: router labels Jan 29, 2016
@NathanWalker
Copy link
Contributor Author

@btford I wanted to check in with you on this. I am planning to finish this up over the next week regarding @tagazok's comment. If you have any additional comments (or know of any current blockers), please let me know.

@mhevery mhevery assigned mhevery and btford and unassigned btford and mhevery Mar 22, 2016
@mhevery
Copy link
Contributor

mhevery commented Mar 22, 2016

@btford Is this something you can finish, or would you like me to take this over?

@NathanWalker
Copy link
Contributor Author

@mhevery I was digging into this today making progress with the changes but when I tried to run gulp build and gulp build.js and begin some testing, I ran into this:

[12:27:49] Starting '!bundle.js.min'...

<--- Last few GCs --->

  118341 ms: Mark-sweep 1375.9 (1457.2) -> 1380.0 (1457.2) MB, 1294.5 / 0 ms [allocation failure] [GC in old space requested].
  119684 ms: Mark-sweep 1380.0 (1457.2) -> 1380.0 (1457.2) MB, 1342.5 / 0 ms [allocation failure] [GC in old space requested].
  121040 ms: Mark-sweep 1380.0 (1457.2) -> 1375.0 (1457.2) MB, 1356.7 / 0 ms [last resort gc].
  122360 ms: Mark-sweep 1375.0 (1457.2) -> 1375.9 (1457.2) MB, 1319.4 / 0 ms [last resort gc].


<--- JS stacktrace --->

==== JS stack trace =========================================

Security context: 0x28fcd09e3ac1 <JS Object>
    2: walkExpressionStatement [/Users/nathan/Documents/github/angular2-stuff/angular/node_modules/webpack/lib/Parser.js:~359] [pc=0x34cb71fb21f0] (this=0x29abbdb4cc31 <a Parser with map 0x225cbae57b39>,statement=0x376226578579 <a Node with map 0x3412f6f158d1>)
    3: walkStatement [/Users/nathan/Documents/github/angular2-stuff/angular/node_modules/webpack/lib/Parser.js:351] [pc=0x34cb71b9561b]...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - process out of memory
Abort trap: 6

I have had trouble historically with this project build unfortunately. This is after removing node_modules and running npm install from a clean slate.

If you know a quick fix for the above would be appreciated. At moment I'm stuck unable to proceed on this feature.

@NathanWalker
Copy link
Contributor Author

My system specs are more than adequate I would think:
3.1 GHz Intel Core i7
16 GB 1867 MHz DDR3
Intel Iris Graphics 1536
300 GB available

@NathanWalker
Copy link
Contributor Author

Just went searching and found this:
#5229
Will try the workaround.

@NathanWalker
Copy link
Contributor Author

Curious if anyone could comment on this issue: #4943
If that sounds reasonable, I'm thinking tackling the refactor first before finishing this would be great since it would affect this PR. I would likely implement the changes here from scratch in a new PR with the refactor in place.

@mhevery
Copy link
Contributor

mhevery commented May 25, 2016

This is obsolete by the new router work. :-(

This PR is stale (does not rebase; pass CI; had no activity for a while). It is probably our fault, and we are sorry. In an effort to keep our PR queue under control, and prevent us from taking too long to get back to you we are cleaning up the queue. Unfortunately this means that this PR is getting closed.

If you would like to resurrect this change, please rebase on master, make the tests pass and create a new PR.

@mhevery mhevery closed this May 25, 2016
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes feature Issue that requests a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

location: should have a .search() method