-
-
Notifications
You must be signed in to change notification settings - Fork 7
History
with the history api in domino-mvp we can get the current url token or update the the current url token. to obtain an instance of the history class in anywhere you can call ClientApp.make().history()
or in a presenter you can use the shortcut method history()
once you obtained the instance you can use it to update or read the current url token.
to get the current url token use history().currentToken()
, every time this method is called it will return a new HistoryToken
instance. once a token is obtained we can use it to manipulate the token instance, use one of the following methods to make changes to the token or ask for information from the token :
-
boolean startsWithPath(String path)
: returns true if the token starts with the path. -
boolean endsWithPath(String path)
: returns true if the paths part ends with the path. -
boolean containsPath(String path)
: returns true if the paths contains the path. -
List<String> paths()
: returns a list of all paths in the token. -
String path()
: returns the paths part of the token as a String. -
HistoryToken appendPath(String path)
: add a new path at the end the token path. -
HistoryToken replacePath(String path, String replacement)
: replace a specific path with a new one. -
HistoryToken replaceAllPaths(String newPath)
: replace all paths with a new path. -
HistoryToken removePath(String path)
: removes a specific path from the token. -
HistoryToken replaceLastPath(String replacement)
: replace the last path in token with a new path. -
HistoryToken clearPaths()
: remove all paths from the token. -
boolean fragmentsStartsWith(String fragment)
: return true if the part after the#
starts with the fragment. -
boolean endsWithFragment(String fragment)
: return true if the part after the#
ends with the fragment. -
boolean containsFragment(String fragment)
: return true if the part after the#
contains the fragment. -
List<String> fragments()
: return a list of fragments. -
HistoryToken replaceLastFragment(String replacement)
: replace the last fragment with a new one. -
HistoryToken removeFragment(String fragment)
: remove a specific fragment. -
HistoryToken appendFragment(String fragment)
: append a fragment at the end of the fragments -
HistoryToken clearFragments()
: clear all fragments. -
HistoryToken replaceFragment(String fragment, String replacement)
: replace a fragment with a new one. -
HistoryToken replaceAllFragments(String newFragment)
: replace all fragments with a new one. -
String fragment()
: return the fragments as a String. -
Map<String, String> queryParameters()
: returns a map of all query parameters. -
boolean hasQueryParameter(String name)
: returns true if there is a query name with the specified name. -
String getQueryParameter(String name)
: return the value of the specified query parametr. -
HistoryToken appendParameter(String name, String value)
: add a new query parameter. -
HistoryToken replaceParameter(String name, String replacementName, String replacementValue)
: replace a query parameter with a new one. -
HistoryToken removeParameter(String name)
: removes a query parameter. -
HistoryToken replaceQuery(String newQuery)
: replace all query part with a new one. -
HistoryToken clearQuery()
: remove all query parameters. -
String query()
: return the query parameters as a String. -
boolean isEmpty()
: returns true if the token is empty. -
HistoryToken clear()
: remove all paths, query parameters and fragments and makes the token empty. -
String value()
: return the token as a String.
after manipulating the token we can update the browser URL, using one of the history fireState
method variants :
-
fireState(String token, String title, String data)
: fire a token value and change the page title and store some data. -
fireState(String token, String title, String data, TokenParameter... parameters)
: fire the token value and the change the page title, and replace any variable parameters - parts starts with:
with the values fromTokenParameters
. -
fireState(String token)
: fire the specified token value. -
void fireState(String token, TokenParameter... parameters)
: fire the token and replace any variable parameters - parts starts with:
with the values fromTokenParameters
.
to change the url wihtout firing events, use the variants of the pushState
method.
Sample :
public void onMovieSelected(String movieName){
HistoryToken historyToken = history().currentToken();
historyToken.appendPath(":movieName");
history().fireState(historyToken.value(), TokenParameter.of("movieName", movieName));
}
history is very important since it is the main mechanism to route between presenters.