Flux Pattern
Implemented by libraries like redux.
Prop drilling
When data is being passed down at almost every level until gets to the final destination.
# Communication
# UML diagram
import { Context, Observer } from "hermes-io";
export const ProductsObserver = new Observer();
export const ProductsContext = new Context('ProductsContext'); # CODE TIME
import { Context, Observer } from "hermes-io";
export const ProductsObserver = new Observer();
export const ProductsContext = new Context('ProductsContext'); # CODE TIME
import { Context, Observer } from "hermes-io";
export const ProductsObserver = new Observer();
export const ProductsContext = new Context('ProductsContext'); # CODE TIME
import { useObserver } from 'hermes-io';
export const useProducts = () => {
const addProduct = () => {};
const removeProduct = () => {};
const handleProductsNotification = (event) => {
const { value = '' } = event;
const { type, payload } = value;
if (type === ADD_PRODUCTS) addProduct(payload);
if (type === REMOVE_PRODUCTS) removeProduct(payload);
};
useObserver({
contexts: [ProductsContext],
observer: ProductsObserver,
listener: handleProductsNotification,
});
}# CODE TIME
import { useObserver } from 'hermes-io';
export const useProducts = () => {
const addProduct = () => {};
const removeProduct = () => {};
const handleProductsNotification = (event) => {
const { value = '' } = event;
const { type, payload } = value;
if (type === ADD_PRODUCTS) addProduct(payload);
if (type === REMOVE_PRODUCTS) removeProduct(payload);
};
useObserver({
contexts: [ProductsContext],
observer: ProductsObserver,
listener: handleProductsNotification,
});
}# CODE TIME
import { useObserver } from 'hermes-io';
export const useProducts = () => {
const addProduct = () => {};
const removeProduct = () => {};
const handleProductsNotification = (event) => {
const { value = '' } = event;
const { type, payload } = value;
if (type === ADD_PRODUCTS) addProduct(payload);
if (type === REMOVE_PRODUCTS) removeProduct(payload);
};
useObserver({
contexts: [ProductsContext],
observer: ProductsObserver,
listener: handleProductsNotification,
});
}# CODE TIME
import { useObserver } from 'hermes-io';
export const useProducts = () => {
const addProduct = () => {};
const removeProduct = () => {};
const handleProductsNotification = (event) => {
const { value = '' } = event;
const { type, payload } = value;
if (type === ADD_PRODUCTS) addProduct(payload);
if (type === REMOVE_PRODUCTS) removeProduct(payload);
};
useObserver({
contexts: [ProductsContext],
observer: ProductsObserver,
listener: handleProductsNotification,
});
}# CODE TIME
import { useObserver } from 'hermes-io';
export const useProducts = () => {
const addProduct = () => {};
const removeProduct = () => {};
const handleProductsNotification = (event) => {
const { value = '' } = event;
const { type, payload } = value;
if (type === ADD_PRODUCTS) addProduct(payload);
if (type === REMOVE_PRODUCTS) removeProduct(payload);
};
useObserver({
contexts: [ProductsContext],
observer: ProductsObserver,
listener: handleProductsNotification,
});
}# CODE TIME
const handleAddProduct = (product = {}) => {
ProductsObservers.notify({
value: {
type: ADD_PRODUCTS,
payload: product
},
context: ProductsContext
});
};# CODE TIME
const handleRemoveProduct = (product = {}) => {
ProductsObservers.notify({
value: {
type: REMOVE_PRODUCTS,
payload: product
},
context: ProductsContext
});
};# DEMO TIME
Chrome Extension