Skip to content

Commit

Permalink
Tweaks and enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
vegegoku committed Jun 26, 2024
1 parent 7363e26 commit 21677d9
Show file tree
Hide file tree
Showing 9 changed files with 157 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,14 @@ public AbstractChildRoutingTask(P parent, C presenter) {
bind(parent, presenter);
this.listener =
state -> {
if (parent.isActive()) {
presenter.setRoutingState(state);
presenter.activate();
}
presenter.setRoutingState(state);
presenter.activate();
};
this.history.listen(presenter.getTokenFilter(), listener);
}

protected void bind(P parent, C child) {
child.setParent(parent);
child.onBindParent(parent);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,32 @@ public P getParent() {
return parent;
}

TokenFilter tokenFilter() {
@Override
protected boolean isHashBasedRouting() {
return super.isHashBasedRouting() || getParent().isHashBasedRouting();
}

protected TokenFilter tokenFilter() {
String path = getRoutingPath();
if (isNull(path) || path.trim().isEmpty()) {
return getParent().getTokenFilter();
} else {
String parentPath = getParent().getRoutingPath();
if (isNull(parentPath) || parentPath.trim().isEmpty()) {
return TokenFilter.startsWithPathFilter(getRoutingPath());
return isHashBasedRouting()
? TokenFilter.startsWithFragment(getRoutingPath())
: TokenFilter.startsWithPathFilter(getRoutingPath());
} else {
return TokenFilter.startsWithPathFilter(parentPath + getRoutingPath());
if (getParent().isHashBasedRouting()) {
return TokenFilter.startsWithFragment(parentPath + getRoutingPath());
} else {
if (isHashBasedRouting()) {
return CompositeFilter.of(
getParent().getTokenFilter(), TokenFilter.startsWithFragment(getRoutingPath()));
} else {
return TokenFilter.startsWithPathFilter(parentPath + getRoutingPath());
}
}
}
}
}
Expand All @@ -54,4 +70,6 @@ void doActivate() {
void setParent(P parent) {
this.parent = parent;
}

public void onBindParent(P parent) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright © 2019 Dominokit
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.dominokit.brix.api;

import org.dominokit.domino.history.HistoryToken;
import org.dominokit.domino.history.NormalizedToken;
import org.dominokit.domino.history.TokenFilter;

public class CompositeFilter implements TokenFilter {

private final TokenFilter root;
private final TokenFilter[] subFilters;

public static CompositeFilter of(TokenFilter root, TokenFilter... subFilters) {
return new CompositeFilter(root, subFilters);
}

public CompositeFilter(TokenFilter root, TokenFilter... subFilters) {
this.root = root;
this.subFilters = subFilters;
}

@Override
public boolean filter(HistoryToken token) {
return root.filter(token) && TokenFilter.and(subFilters).filter(token);
}

@Override
public NormalizedToken normalizeToken(String rootPath, String token) {
return root.normalizeToken(rootPath, token);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright © 2019 Dominokit
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.dominokit.brix.api;

import java.util.Set;

public interface HasContext<T> {

default void update(T context) {
getContextListeners()
.forEach(
contextListener -> {
contextListener.onContextUpdated(context);
});
}

Set<ContextListener<? super T>> getContextListeners();

default T registerContextListener(ContextListener<? super T> contextListener) {
getContextListeners().add(contextListener);
return (T) this;
}

default T removeChangeListener(ContextListener<? super T> contextListener) {
getContextListeners().remove(contextListener);
return (T) this;
}

interface ContextListener<T> {
void onContextUpdated(T context);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright © 2019 Dominokit
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.dominokit.brix.api;

public interface HasUiHandlers<U extends UiHandlers> {
U getUiHandlers();
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,22 @@ public String getRoutingPath() {
return "";
}

TokenFilter tokenFilter() {
protected boolean isHashBasedRouting() {
String path = getRoutingPath();
if (nonNull(path) && !path.isEmpty()) {
return path.contains("#");
}
return false;
}

protected TokenFilter tokenFilter() {
String path = getRoutingPath();
if (isNull(path) || path.trim().isEmpty()) {
return TokenFilter.any();
} else {
return TokenFilter.startsWithPathFilter(path);
return isHashBasedRouting()
? TokenFilter.startsWithFragment(path)
: TokenFilter.startsWithPathFilter(path);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,25 @@
import elemental2.dom.Element;
import org.dominokit.brix.api.AttachableAware;
import org.dominokit.brix.api.AttachableBinder;
import org.dominokit.brix.api.HasUiHandlers;
import org.dominokit.brix.api.UiHandlers;
import org.dominokit.brix.api.View;
import org.dominokit.domino.ui.utils.BaseDominoElement;

public abstract class BrixView<E extends Element, U extends UiHandlers>
extends BaseDominoElement<E, BrixView<E, U>> implements View {
extends BaseDominoElement<E, BrixView<E, U>> implements View, HasUiHandlers<U> {

private AttachableBinder attachableBinder;

protected U handlers() {
return null;
}

@Override
public U getUiHandlers() {
return handlers();
}

@Override
public AttachableBinder getAttachableBinder() {
if (isNull(attachableBinder)) {
Expand Down
3 changes: 2 additions & 1 deletion domino-brix-processor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,18 @@
<description>The annotation processor to generate domino-brix components</description>
<url>https://github.com/DominoKit/domino-brix</url>


<dependencies>
<dependency>
<groupId>org.dominokit</groupId>
<artifactId>domino-brix-client</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.dominokit</groupId>
<artifactId>domino-brix-shared</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.dominokit</groupId>
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@
<elemental2.version>1.2.1</elemental2.version>
<gwt.i18n.version>1.0.2</gwt.i18n.version>

<domino.history.version>1.0.3</domino.history.version>
<domino.ui.version>2.0.1</domino.ui.version>
<domino.history.version>HEAD-SNAPSHOT</domino.history.version>
<domino.ui.version>HEAD-SNAPSHOT</domino.ui.version>
<domino.auto.version>1.0.2</domino.auto.version>
<dagger.version>2.51.1</dagger.version>
</properties>
Expand Down

0 comments on commit 21677d9

Please sign in to comment.