Skip to content

Commit

Permalink
initial version
Browse files Browse the repository at this point in the history
  • Loading branch information
vegegoku committed May 25, 2019
1 parent ae5a192 commit c1c6b69
Show file tree
Hide file tree
Showing 31 changed files with 2,803 additions and 12 deletions.
66 changes: 54 additions & 12 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,54 @@
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties

# Avoid ignoring Maven wrapper jar file (.jar files are usually ignored)
!/.mvn/wrapper/maven-wrapper.jar
**/target/

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
**/*.ear

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
**/*.class

# Package Files #
**/src/main/webapp/**/*.jar
**/*.war

# gwt caches and compiled units #
src/main/webapp/gwt_bree/
**/gwt-unitCache/

# boilerplate generated classes #
**/.apt_generated/


# more caches and things from deploy #
**/src/main/webapp/WEB-INF/deploy/
**/src/main/webapp/WEB-INF/classes/

#compilation logs
**/.gwt/

#gwt junit compilation files
**/www-test/

**/dependency-reduced-pom.xml
**/buildNumber.properties
**/.mvn/timing.properties

# Eclipse
**/.classpath
**/.project
**/.settings/

# Intellij
**/.idea/
**/*.iml
**/*.iws

.idea/**/*.*
**/*.iml
**/*.iws
**/*.log

**/bin/
31 changes: 31 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
sudo: false
language: java
jdk: openjdk8
branches:
only:
- master
cache:
directories:
- "$HOME/.m2"
install: true
notifications:
webhooks:
urls:
- https://webhooks.gitter.im/e/a434c0997c2c1629fef2
on_success: change
on_failure: always
on_start: never
after_success:
- openssl aes-256-cbc -pass pass:$ENCRYPTION_PASSWORD -in $GPG_DIR/pubring.gpg.enc
-out $GPG_DIR/pubring.gpg -d
- openssl aes-256-cbc -pass pass:$ENCRYPTION_PASSWORD -in $GPG_DIR/secring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Xb9IxlZ80L16JqHYXaOAzDsGED041EJOHBPKCrEtrufPNolmtiIHJmc87xu+MXsFW2ki7/nqb7o1NIt8o4XIE3UG8MOL6WJxggiMRf0lge2Gmz8YceCyJpAWm8S9RwOcecki0WUuY5F60vW2CttTlARU4tgjzVIp8Heh58ujOCk93MJV+axGmwvBuqrLCCbkLA/qFEqEhBhaeMAnlDMi1zpOuwnvjYu/yv2t6N5lMp6LJKVEmScf38EZr5VSC5QTKYgu9CEPVnZldkOrGCv78OG8qJmcraeAObrOE=
137 changes: 137 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,139 @@
# domino-history
A wrapper for browser history state API

### Maven dependencies

```xml
<dependency>
<groupId>org.dominokit</groupId>
<artifactId>domino-history-gwt</artifactId>
<version>1.0-rc.4-SNAPSHOT</version>
</dependency>
```

### GWT inherits

`<inherits name="org.dominokit.domino.gwt.history.History"/>`

### Usage

1- Create a `StateHistory` instance.

`StateHistory history = new StateHistory()`

2- Use `pushState(String token)` to change the window url without firing the events.
3- Use `fireState(String token)` to change the window url and fire the events.
4- Use `listen` with all it variants to start listing for url changes.
5- Use `currentToken` to get the current active token in the browser window url.

#### Sample

```java
public class App implements EntryPoint {

private StateHistory history = new StateHistory();

public void onModuleLoad() {

history.listen(TokenFilter.any(), state -> {
console.info(state.token().value());
});
history.listen(TokenFilter.startsWithPathFilter("path1"), state -> {
console.info(state.token().value());
});

HTMLButtonElement button1 = Js.uncheckedCast(document.createElement("button"));
button1.textContent ="button1";
button1.addEventListener("click", evt -> history.pushState("path1/path2"));

HTMLButtonElement button2 = Js.uncheckedCast(document.createElement("button"));
button2.textContent ="button2";
button2.addEventListener("click", evt -> history.fireState("path3/path4"));

HTMLButtonElement button3 = Js.uncheckedCast(document.createElement("button"));
button3.textContent ="button3";
button3.addEventListener("click", evt -> console.info("current token : "+history.currentToken().value()));

document.body.appendChild(button1);
document.body.appendChild(button2);
document.body.appendChild(button3);

}
}
```

### The HistoryToken

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 removeLastPath(String path)` : removes the last path part 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.

### Token Filters

Use one of the filters from `TokenFilter` to narrow the tokens you want to listen to from history, the TokenFilter class has factory method for lots of useful filters.

- Sample

```java
history.listen(TokenFilter.any(), state -> {
console.info(state.token().value());
});
history.listen(TokenFilter.startsWithPathFilter("path1"), state -> {
console.info(state.token().value());
});
```

### Wildcards

Sometimes we want to listen to token where a specific part of it is a variable, in this case we can simply define that part as a variable using `:` in the token filter when we define a listener.

- Sample

```java
HTMLButtonElement button4 = Js.uncheckedCast(document.createElement("button"));
button4.textContent ="button4";
button4.addEventListener("click", evt -> history.fireState("fixedPath/somePath"));

history.listen(TokenFilter.endsWith("fixedPath/:variablePath"), state -> {
String variablePathValue = state.normalizedToken().getPathParameter("variablePath");
console.info(variablePathValue);
//when the button clicked should print somePath
});
```



8 changes: 8 additions & 0 deletions deploy/publish.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

echo $GPG_DIR
echo "-----------------------------------"
if [[ $TRAVIS_PULL_REQUEST == "false" ]]; then
mvn clean deploy -Dmaven.test.skip=true --settings $GPG_DIR/settings.xml -Dci=true
exit $?
fi
Binary file added deploy/pubring.gpg.enc
Binary file not shown.
Binary file added deploy/secring.gpg.enc
Binary file not shown.
9 changes: 9 additions & 0 deletions deploy/settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<settings>
<servers>
<server>
<id>ossrh</id>
<username>${env.SONATYPE_USERNAME}</username>
<password>${env.SONATYPE_PASSWORD}</password>
</server>
</servers>
</settings>
65 changes: 65 additions & 0 deletions domino-history-gwt/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>domino-history</artifactId>
<groupId>org.dominokit</groupId>
<version>1.0-rc.4-SNAPSHOT</version>
</parent>
<packaging>gwt-lib</packaging>
<modelVersion>4.0.0</modelVersion>

<artifactId>domino-history-gwt</artifactId>

<name>domino-history-gwt</name>
<url>https://github.com/DominoKit/domino-history</url>

<dependencies>

<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
<version>2.8.2</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.dominokit</groupId>
<artifactId>domino-history-shared</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.dominokit</groupId>
<artifactId>domino-history-shared</artifactId>
<version>${project.version}</version>
<classifier>sources</classifier>
</dependency>

<dependency>
<groupId>com.google.elemental2</groupId>
<artifactId>elemental2-core</artifactId>
<version>${elemental.version}</version>
</dependency>

<dependency>
<groupId>com.google.elemental2</groupId>
<artifactId>elemental2-dom</artifactId>
<version>${elemental.version}</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>net.ltgt.gwt.maven</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<moduleName>org.dominokit.domino.gwt.history.History</moduleName>
<moduleShortName>dominogwthistory</moduleShortName>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.dominokit.domino.gwt.history;

import jsinterop.annotations.JsPackage;
import jsinterop.annotations.JsType;

@JsType(isNative = true, namespace = JsPackage.GLOBAL)
public class History {
public native void back();

public native void forward();

public native void pushState(JsState jsState, String title, String url);

public native void replaceState(JsState jsState, String title, String url);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package org.dominokit.domino.gwt.history;

import org.dominokit.domino.history.DominoHistory;
import org.dominokit.domino.history.TokenFilter;

public class HistoryListener {
private final DominoHistory.StateListener listener;

private final TokenFilter tokenFilter;

private final boolean removeOnComplete;

private HistoryListener(DominoHistory.StateListener listener,
TokenFilter tokenFilter) {
this.listener = listener;
this.tokenFilter = tokenFilter;
this.removeOnComplete = false;
}

HistoryListener(DominoHistory.StateListener listener,
TokenFilter tokenFilter, boolean removeOnComplete) {
this.listener = listener;
this.tokenFilter = tokenFilter;
this.removeOnComplete = removeOnComplete;
}

public DominoHistory.StateListener getListener() {
return listener;
}

public TokenFilter getTokenFilter() {
return tokenFilter;
}

public boolean isRemoveOnComplete() {
return removeOnComplete;
}
}
Loading

0 comments on commit c1c6b69

Please sign in to comment.