@willgmbr
Grau em que um módulo depende ou se interliga com outros:
function CoffeeMaker() {
var grinder = new Grinder();
var pump = Pump.getInstance();
var heater = app.get('Heater');
this.brew = function() {
grinder.grind();
heater.on();
pump.pump();
};
}
function CoffeeMaker(
grinder,
pump,
heater ) {
this.brew = function() {
grinder.grind();
heater.on();
pump.pump();
};
}
function main() {
let electricity = new Electricity();
let grinder = new Grinder(electricity);
let heater = new Heater(electricity);
let pump = new Pump(heater, electricity);
let coffeeMaker = new CoffeeMaker(grinder,
pump, heater);
coffeeMaker.brew();
}
function main() {
let logger = new Logger();
let electricity = new Electricity(logger);
let grinder = new Grinder(electricity, logger);
let heater = new Heater(electricity, logger);
let pump = new Pump(heater, electricity, logger);
let coffeeMaker = new CoffeeMaker(grinder, pump,
heater, logger);
coffeeMaker.brew();
}
function main() {
let injector = new Injector();
let coffeeMaker = injector.get(CoffeeMaker);
coffeeMaker.brew();
}
import {Inject} from 'di/annotations';
import {Grinder} from './grinder';
import {Pump} from './pump';
import {Heater} from './heater';
@Inject(Grinder, Pump, Heater)
export class CoffeeMaker {
constructor(grinder, pump, heater) {
// ...
}
brew() {
console.log('Brewing a coffee...');
}
}
import {Grinder} from './grinder';
import {Pump} from './pump';
import {Heater} from './heater';
export class CoffeeMaker {
constructor(
private grinder: Grinder,
private pump: Pump,
private heater: Heater) {
}
brew() {
console.log('Brewing a coffee...');
}
}
class MyMediator() {
constructor() {
this.model = new MyModel();
this.view1 = new View1(this.model);
this.view2 = new View2();
}
class MyMediator() {
constructor() {
this.model = new MyModel();
this.view1 = new View1(this.model);
this.view2 = new View2();
}
start() {
this.view1.on('my-event', () => {
this.view2.updateSomething();
});
}
}
Dados
Eventos
Mediator
const todosReducer = (state = [], action) => {
const { type, payload } = action;
const todosReducer = (state = [], action) => {
const { type, payload } = action;
switch(type){
case ADD_ITEM:
return [
...state,
payload
];
const todosReducer = (state = [], action) => {
const { type, payload } = action;
switch(type){
case ADD_ITEM:
return [
...state,
payload
];
case REMOVE_ITEM:
return state.filter(
item => item.id !== payload.id
);
const todosReducer = (state = [], action) => {
const { type, payload } = action;
switch(type){
case ADD_ITEM:
return [
...state,
payload
];
case REMOVE_ITEM:
return state.filter(
item => item.id !== payload.id
);
default:
return state;
}
}
@willgmbr
fb.com/wgrasel