SlideShare uma empresa Scribd logo
1 de 25
Baixar para ler offline
NGRX
MetaReducer
@eliraneliassy
About mySelf
• Experienced FE developer, specialised in B2C applications
• FE trainer & lecturer @ 500Tech
• Weekends FE developer @ fashbash.co
Let’s build a strong Angular
community together!!
Whats new in NGRX V7?
Breaking changes
ofType
import { Effect, Actions } from '@ngrx/effects';
@Injectable()
export class MyEffects {
@Effect()
someEffect$: Observable<Action> = this.actions$
.ofType(UserActions.LOGIN)
.pipe(map(() => new AnotherAction()));
constructor(private actions$: Actions) { }
}
Breaking changes
ofType
import { Effect, Actions, ofType } from '@ngrx/effects';
@Injectable()
export class MyEffects {
@Effect()
someEffect$: Observable<Action> = this.actions$.pipe(
ofType(UserActions.LOGIN), // use the pipeable ofType operator
map(() => new AnotherAction())
);
constructor(private actions$: Actions<UserActions>) {}
}
Selectors props
export const getCount = createSelector(
getCounterValue,
(counter, props) => counter * props.multiply);
this.store.pipe(select(fromRoot.getCount, { multiply: 2 }))
Testing - ProvideMockStore
describe('Mock Store', () => {
let mockStore: MockStore<{ counter1: number, counter2: number }>;
beforeEach(() => {
const initialState = { counter1: 0, counter2: 1 };
TestBed.configureTestingModule({
providers: [
provideMockStore({ initialState })
],
});
mockStore = TestBed.get(Store);
});
it('should set the new state', () => {
mockStore.setState({ counter1: 1, counter2: 2 });
mockStore.pipe(take(1)).subscribe(state => {
expect(state.counter1).toBe(1);
});
});
});
Testing - ProvideMockStore
describe('Mock Store', () => {
let mockStore: MockStore<{ counter1: number, counter2: number }>;
beforeEach(() => {
const initialState = { counter1: 0, counter2: 1 };
TestBed.configureTestingModule({
providers: [
provideMockStore({ initialState })
],
});
mockStore = TestBed.get(Store);
});
it('should set the new state', () => {
mockStore.setState({ counter1: 1, counter2: 2 });
mockStore.pipe(take(1)).subscribe(state => {
expect(state.counter1).toBe(1);
});
});
});
Effects - Life cycle
import { OnInitEffects } from '@ngrx/effects';
class UserEffects implements OnInitEffects, OnIdentifyEffects {
constructor(private effectIdentifier: string) {}
ngrxOnInitEffects(): Action {
return { type: '[UserEffects]: Init' };
}
ngrxOnIdentifyEffects() {
return this.effectIdentifier;
}
}
And more…
New entity adapter
New actions on the RouterStoreModule
StoreDevTools enrichment
NGRX-data
NGRX metaReducer
What are meta reducers?
What are meta reducers?
MetaReducers are hooks into the action->reducer
pipeline. They allow us to pre-process actions
before normal reducers are invoked.
What are meta reducers?
MetaReducers are hooks into the action->reducer
pipeline. They allow us to pre-process actions
before normal reducers are invoked.
Or in other words:
“MetaReducers are Redux middleware “
Meta Reducers
Meta reducers get reducer,
state and action and return new
state
MetaReducers API
Demo App
App Objectives:
Create “User Preferences” which saves all
user choices:
Every user action will be saved to both client
store and localStorage
When re-starting the application - The store
sync with the latest state from the
localStorage
Live coding…
Thank You
@EliranEliassy eliran.eliassy@gmail.comeliraneliassy

Mais conteúdo relacionado

Mais procurados

Mais procurados (20)

Angular2 workshop
Angular2 workshopAngular2 workshop
Angular2 workshop
 
Exploring Angular 2 - Episode 2
Exploring Angular 2 - Episode 2Exploring Angular 2 - Episode 2
Exploring Angular 2 - Episode 2
 
Angular 2.0 - What to expect
Angular 2.0 - What to expectAngular 2.0 - What to expect
Angular 2.0 - What to expect
 
Workshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testingWorkshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testing
 
An introduction to Angular2
An introduction to Angular2 An introduction to Angular2
An introduction to Angular2
 
Angular2 - In Action
Angular2  - In ActionAngular2  - In Action
Angular2 - In Action
 
Http Communication in Angular 2.0
Http Communication in Angular 2.0Http Communication in Angular 2.0
Http Communication in Angular 2.0
 
Jquery- One slide completing all JQuery
Jquery- One slide completing all JQueryJquery- One slide completing all JQuery
Jquery- One slide completing all JQuery
 
Upgrading from Angular 1.x to Angular 2.x
Upgrading from Angular 1.x to Angular 2.xUpgrading from Angular 1.x to Angular 2.x
Upgrading from Angular 1.x to Angular 2.x
 
Data Flow Patterns in Angular 2 - Sebastian Müller
Data Flow Patterns in Angular 2 -  Sebastian MüllerData Flow Patterns in Angular 2 -  Sebastian Müller
Data Flow Patterns in Angular 2 - Sebastian Müller
 
AngularJs
AngularJsAngularJs
AngularJs
 
Angular Dependency Injection
Angular Dependency InjectionAngular Dependency Injection
Angular Dependency Injection
 
Angular 2 NgModule
Angular 2 NgModuleAngular 2 NgModule
Angular 2 NgModule
 
AngularJS (1.x) as fast as a lightning
AngularJS (1.x)as fast as a lightningAngularJS (1.x)as fast as a lightning
AngularJS (1.x) as fast as a lightning
 
Routing And Navigation
Routing And NavigationRouting And Navigation
Routing And Navigation
 
Firebase ng2 zurich
Firebase ng2 zurichFirebase ng2 zurich
Firebase ng2 zurich
 
Reactive Programming with JavaScript
Reactive Programming with JavaScriptReactive Programming with JavaScript
Reactive Programming with JavaScript
 
Unit Testing Express and Koa Middleware in ES2015
Unit Testing Express and Koa Middleware in ES2015Unit Testing Express and Koa Middleware in ES2015
Unit Testing Express and Koa Middleware in ES2015
 
AngularJs $provide API internals & circular dependency problem.
AngularJs $provide API internals & circular dependency problem.AngularJs $provide API internals & circular dependency problem.
AngularJs $provide API internals & circular dependency problem.
 
Understanding Angular 2 - Shmuela Jacobs - Codemotion Milan 2016
Understanding Angular 2 - Shmuela Jacobs - Codemotion Milan 2016Understanding Angular 2 - Shmuela Jacobs - Codemotion Milan 2016
Understanding Angular 2 - Shmuela Jacobs - Codemotion Milan 2016
 

Semelhante a Ngrx meta reducers

Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STMConcurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
Mario Fusco
 

Semelhante a Ngrx meta reducers (20)

Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STMConcurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
 
React hooks
React hooksReact hooks
React hooks
 
Battle of React State Managers in frontend applications
Battle of React State Managers in frontend applicationsBattle of React State Managers in frontend applications
Battle of React State Managers in frontend applications
 
2. Design patterns. part #2
2. Design patterns. part #22. Design patterns. part #2
2. Design patterns. part #2
 
[FEConf Korea 2017]Angular 컴포넌트 대화법
[FEConf Korea 2017]Angular 컴포넌트 대화법[FEConf Korea 2017]Angular 컴포넌트 대화법
[FEConf Korea 2017]Angular 컴포넌트 대화법
 
Dependency Injection for Android
Dependency Injection for AndroidDependency Injection for Android
Dependency Injection for Android
 
Dependency Injection for Android @ Ciklum speakers corner Kiev 29. May 2014
Dependency Injection for Android @ Ciklum speakers corner Kiev 29. May 2014Dependency Injection for Android @ Ciklum speakers corner Kiev 29. May 2014
Dependency Injection for Android @ Ciklum speakers corner Kiev 29. May 2014
 
What is new in sulu 2.0
What is new in sulu 2.0What is new in sulu 2.0
What is new in sulu 2.0
 
Build Widgets
Build WidgetsBuild Widgets
Build Widgets
 
The evolution of redux action creators
The evolution of redux action creatorsThe evolution of redux action creators
The evolution of redux action creators
 
Functional UIs with Java 8 and Vaadin JavaOne2014
Functional UIs with Java 8 and Vaadin JavaOne2014Functional UIs with Java 8 and Vaadin JavaOne2014
Functional UIs with Java 8 and Vaadin JavaOne2014
 
ReactiveCocoa in Practice
ReactiveCocoa in PracticeReactiveCocoa in Practice
ReactiveCocoa in Practice
 
Ngrx slides
Ngrx slidesNgrx slides
Ngrx slides
 
AngularJS - Services
AngularJS - ServicesAngularJS - Services
AngularJS - Services
 
Testing Android apps based on Dagger and RxJava Droidcon UK
Testing Android apps based on Dagger and RxJava Droidcon UKTesting Android apps based on Dagger and RxJava Droidcon UK
Testing Android apps based on Dagger and RxJava Droidcon UK
 
Side effects-con-redux
Side effects-con-reduxSide effects-con-redux
Side effects-con-redux
 
Angular 16 – the rise of Signals
Angular 16 – the rise of SignalsAngular 16 – the rise of Signals
Angular 16 – the rise of Signals
 
Clean Javascript
Clean JavascriptClean Javascript
Clean Javascript
 
A GWT Application with MVP Pattern Deploying to CloudFoundry using Spring Roo
A GWT Application with MVP Pattern Deploying to CloudFoundry using  Spring Roo A GWT Application with MVP Pattern Deploying to CloudFoundry using  Spring Roo
A GWT Application with MVP Pattern Deploying to CloudFoundry using Spring Roo
 
Angular 2 Migration - JHipster Meetup 6
Angular 2 Migration - JHipster Meetup 6Angular 2 Migration - JHipster Meetup 6
Angular 2 Migration - JHipster Meetup 6
 

Mais de Eliran Eliassy (6)

Between JS and AI
Between JS and AIBetween JS and AI
Between JS and AI
 
Angular CDK
Angular CDKAngular CDK
Angular CDK
 
Runtime performance
Runtime performanceRuntime performance
Runtime performance
 
Intro to HTML and CSS basics
Intro to HTML and CSS basicsIntro to HTML and CSS basics
Intro to HTML and CSS basics
 
Angular performance improvments
Angular performance improvmentsAngular performance improvments
Angular performance improvments
 
Generic forms
Generic formsGeneric forms
Generic forms
 

Último

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Último (20)

Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 

Ngrx meta reducers

  • 2. About mySelf • Experienced FE developer, specialised in B2C applications • FE trainer & lecturer @ 500Tech • Weekends FE developer @ fashbash.co
  • 3. Let’s build a strong Angular community together!!
  • 4.
  • 5.
  • 6. Whats new in NGRX V7?
  • 7.
  • 8. Breaking changes ofType import { Effect, Actions } from '@ngrx/effects'; @Injectable() export class MyEffects { @Effect() someEffect$: Observable<Action> = this.actions$ .ofType(UserActions.LOGIN) .pipe(map(() => new AnotherAction())); constructor(private actions$: Actions) { } }
  • 9. Breaking changes ofType import { Effect, Actions, ofType } from '@ngrx/effects'; @Injectable() export class MyEffects { @Effect() someEffect$: Observable<Action> = this.actions$.pipe( ofType(UserActions.LOGIN), // use the pipeable ofType operator map(() => new AnotherAction()) ); constructor(private actions$: Actions<UserActions>) {} }
  • 10. Selectors props export const getCount = createSelector( getCounterValue, (counter, props) => counter * props.multiply); this.store.pipe(select(fromRoot.getCount, { multiply: 2 }))
  • 11. Testing - ProvideMockStore describe('Mock Store', () => { let mockStore: MockStore<{ counter1: number, counter2: number }>; beforeEach(() => { const initialState = { counter1: 0, counter2: 1 }; TestBed.configureTestingModule({ providers: [ provideMockStore({ initialState }) ], }); mockStore = TestBed.get(Store); }); it('should set the new state', () => { mockStore.setState({ counter1: 1, counter2: 2 }); mockStore.pipe(take(1)).subscribe(state => { expect(state.counter1).toBe(1); }); }); });
  • 12. Testing - ProvideMockStore describe('Mock Store', () => { let mockStore: MockStore<{ counter1: number, counter2: number }>; beforeEach(() => { const initialState = { counter1: 0, counter2: 1 }; TestBed.configureTestingModule({ providers: [ provideMockStore({ initialState }) ], }); mockStore = TestBed.get(Store); }); it('should set the new state', () => { mockStore.setState({ counter1: 1, counter2: 2 }); mockStore.pipe(take(1)).subscribe(state => { expect(state.counter1).toBe(1); }); }); });
  • 13. Effects - Life cycle import { OnInitEffects } from '@ngrx/effects'; class UserEffects implements OnInitEffects, OnIdentifyEffects { constructor(private effectIdentifier: string) {} ngrxOnInitEffects(): Action { return { type: '[UserEffects]: Init' }; } ngrxOnIdentifyEffects() { return this.effectIdentifier; } }
  • 14. And more… New entity adapter New actions on the RouterStoreModule StoreDevTools enrichment NGRX-data
  • 16. What are meta reducers?
  • 17. What are meta reducers? MetaReducers are hooks into the action->reducer pipeline. They allow us to pre-process actions before normal reducers are invoked.
  • 18. What are meta reducers? MetaReducers are hooks into the action->reducer pipeline. They allow us to pre-process actions before normal reducers are invoked. Or in other words: “MetaReducers are Redux middleware “
  • 19.
  • 21. Meta reducers get reducer, state and action and return new state MetaReducers API
  • 23. App Objectives: Create “User Preferences” which saves all user choices: Every user action will be saved to both client store and localStorage When re-starting the application - The store sync with the latest state from the localStorage