mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-24 19:34:39 +00:00
docs: improve docs and add explanation for flux (#2928)
This commit is contained in:
@@ -24,19 +24,18 @@
|
||||
*/
|
||||
package com.iluwatar.flux.action;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* ContentAction is a concrete action.
|
||||
*/
|
||||
public class ContentAction extends Action {
|
||||
|
||||
@Getter
|
||||
private final Content content;
|
||||
|
||||
public ContentAction(Content content) {
|
||||
super(ActionType.CONTENT_CHANGED);
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public Content getContent() {
|
||||
return content;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,19 +25,18 @@
|
||||
package com.iluwatar.flux.action;
|
||||
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* MenuAction is a concrete action.
|
||||
*/
|
||||
public class MenuAction extends Action {
|
||||
|
||||
@Getter
|
||||
private final MenuItem menuItem;
|
||||
|
||||
public MenuAction(MenuItem menuItem) {
|
||||
super(ActionType.MENU_ITEM_SELECTED);
|
||||
this.menuItem = menuItem;
|
||||
}
|
||||
|
||||
public MenuItem getMenuItem() {
|
||||
return menuItem;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ import com.iluwatar.flux.view.MenuView;
|
||||
* Flux is the application architecture that Facebook uses for building client-side web
|
||||
* applications. Flux eschews MVC in favor of a unidirectional data flow. When a user interacts with
|
||||
* a React view, the view propagates an action through a central dispatcher, to the various stores
|
||||
* that hold the application's data and business logic, which updates all of the views that are
|
||||
* that hold the application's data and business logic, which updates all the views that are
|
||||
* affected.
|
||||
*
|
||||
* <p>This example has two views: menu and content. They represent typical main menu and content
|
||||
|
||||
@@ -32,12 +32,14 @@ import com.iluwatar.flux.action.MenuItem;
|
||||
import com.iluwatar.flux.store.Store;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* Dispatcher sends Actions to registered Stores.
|
||||
*/
|
||||
public final class Dispatcher {
|
||||
|
||||
@Getter
|
||||
private static Dispatcher instance = new Dispatcher();
|
||||
|
||||
private final List<Store> stores = new LinkedList<>();
|
||||
@@ -45,10 +47,6 @@ public final class Dispatcher {
|
||||
private Dispatcher() {
|
||||
}
|
||||
|
||||
public static Dispatcher getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void registerStore(Store store) {
|
||||
stores.add(store);
|
||||
}
|
||||
|
||||
@@ -28,12 +28,14 @@ import com.iluwatar.flux.action.Action;
|
||||
import com.iluwatar.flux.action.ActionType;
|
||||
import com.iluwatar.flux.action.Content;
|
||||
import com.iluwatar.flux.action.ContentAction;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* ContentStore is a concrete store.
|
||||
*/
|
||||
public class ContentStore extends Store {
|
||||
|
||||
@Getter
|
||||
private Content content = Content.PRODUCTS;
|
||||
|
||||
@Override
|
||||
@@ -44,8 +46,4 @@ public class ContentStore extends Store {
|
||||
notifyChange();
|
||||
}
|
||||
}
|
||||
|
||||
public Content getContent() {
|
||||
return content;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,12 +28,14 @@ import com.iluwatar.flux.action.Action;
|
||||
import com.iluwatar.flux.action.ActionType;
|
||||
import com.iluwatar.flux.action.MenuAction;
|
||||
import com.iluwatar.flux.action.MenuItem;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* MenuStore is a concrete store.
|
||||
*/
|
||||
public class MenuStore extends Store {
|
||||
|
||||
@Getter
|
||||
private MenuItem selected = MenuItem.HOME;
|
||||
|
||||
@Override
|
||||
@@ -44,8 +46,4 @@ public class MenuStore extends Store {
|
||||
notifyChange();
|
||||
}
|
||||
}
|
||||
|
||||
public MenuItem getSelected() {
|
||||
return selected;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user