Irc-Unix.net

Главная | Actual Topics | Обратная связь | Guest Book | В избранное | Сделать домашней
Категории
 System & Utilities
 Unix News
 OS Emulator
 Developing
 Learning/Education
 Games
 Humour
Каталог статей
Все статьи

Antispam
Статьи
Биллу Гейтсу тоже предлагают избавиться ...
Вымогательство в борьбе со спамом
Календарь

November, 2017
ПнВтСрЧтПтСбВс
12345
6789101112
13141516171819
20212223242526
27282930
Опросы
Какой из этих ОС Вы отдаете большее предпочтение?

QNX
FreeBSD
Linux(any)
Solaris
Mac OS
Windows XP
Windows 2003
Что такое ОС? :)


Результаты
Другие опросы

Всего голосов: 325
Комментарии: 0
Ссылки

Архив Новостей
 November 2017 (7)
 October 2017 (18)
 September 2017 (18)
 August 2017 (13)
 February 2017 (14)
 January 2017 (19)
 December 2016 (16)
 November 2016 (16)
 October 2016 (21)
 September 2016 (18)
 August 2016 (16)
 July 2016 (16)
 June 2016 (20)
 May 2016 (18)
 April 2016 (15)
 March 2016 (22)
 February 2016 (17)
 January 2016 (15)
 December 2015 (15)
 November 2015 (22)
 October 2015 (20)
 September 2015 (17)
 August 2015 (25)
 July 2015 (20)
 June 2015 (23)
 May 2015 (21)
 April 2015 (17)
 March 2015 (19)
 February 2015 (9)
 January 2015 (23)
 December 2014 (9)
 November 2014 (13)
 October 2014 (12)
 September 2014 (18)
 August 2014 (20)
 July 2014 (10)
 June 2014 (12)
 May 2014 (12)
 April 2014 (10)
 March 2014 (22)
 February 2014 (10)
 January 2014 (8)
 December 2013 (26)
 November 2013 (53)
 October 2013 (40)
 September 2013 (48)
 August 2013 (63)
 July 2013 (56)
 June 2013 (52)
 May 2013 (49)
 April 2013 (67)
 March 2013 (74)
 February 2013 (63)
 January 2013 (62)
 December 2012 (62)
 November 2012 (66)
 October 2012 (68)
 September 2012 (48)
 August 2012 (75)
 July 2012 (60)
 June 2012 (71)
 May 2012 (69)
 April 2012 (85)
 March 2012 (86)
 February 2012 (90)
 January 2012 (81)
 December 2011 (103)
 November 2011 (118)
 October 2011 (74)
 September 2011 (2)
 June 2011 (110)
 May 2011 (118)
 April 2011 (111)
 March 2011 (112)
 February 2011 (101)
 January 2011 (119)
 December 2010 (117)
 November 2010 (118)
 October 2010 (131)
 September 2010 (117)
 August 2010 (226)
 July 2010 (351)
 June 2010 (305)
 May 2010 (319)
 April 2010 (343)
 March 2010 (329)
 February 2010 (311)
 January 2010 (312)
 December 2009 (266)
 November 2009 (156)
 July 2009 (101)
 June 2009 (279)
 May 2009 (365)
 April 2009 (348)
 March 2009 (347)
 February 2009 (323)
 January 2009 (318)
 December 2008 (237)
 November 2008 (155)
 October 2008 (334)
 September 2008 (310)
 August 2008 (343)
 July 2008 (362)
 June 2008 (322)
 May 2008 (604)
 April 2008 (1276)
 March 2008 (1658)
 February 2008 (250)
 January 2008 (6)
 November 2007 (1)
 September 2007 (1)
 June 2007 (1)
 May 2007 (1)
 March 2007 (1)
 January 2007 (2)
 December 2006 (1)
 October 2006 (2)
 September 2006 (1)
 August 2006 (2)

NGRX Store and State Management

System & Utilities

I have seen a couple of times experienced developers finding NGRX difficult to grasp. That was my experience as well. So I'll try to explain what it is about.

https://gitter.im/ngrx/platform

This is a great chat site for getting assistance. The angular/angular chat is active as well.

The best was to start is to lay out the problem that it solves. The Redux pattern implemented in NGRX is a way to maintain application state.

What is application state? All the data that the application requires to build and render the view over time.

Starting from the view, or Component level in Angular, here is how the data is presented by NGRX.

@Component({
   selector: 'article-view',
   template: `<div ngfor="let a of articlelist$ | async">
                  {{a.author}}{{a.title}}
              </div>`  
})
export class ArticleListView {
   articlelist$ = this.store.select(getArticles);

   constructor(private store: Store) {}
}

First you inject the store using the constructor.
Then you assign a value with a selector, in this example, getArticles.

Then in the template articlelist$, an observable is piped through async, returning an array, passed to ngFor which loops through each item and displays the author and title.

State is a list of articles each with a title and author.

export interface Article {
   author: string;
   title: string;
}

export interface ArticleState {
   articlelist: Article[];
}

Then define that application state

export interface State {
   articles: ArticleState;
}

You may hit the first objection to this pattern right here. All you have is a list of objects, why the excessive boilerplate? Believe me it will get worse. In fact for such a simple application, NGRX doesn't really make sense. But fill out this example into a full content display application with users, multiple data sources, complex content structures, multiple developers. Then the boilerplate, the very clear definition of everything in a way that is easy to read becomes very important. Embrace the Boilerplate!

Adding a second state slice will help illustrate the pattern.

export interface State {
    articles: ArticleState;
    auth: AuthState;
    preferences: PreferencesState;
}

Authentication and authorization, and a way to track preferences are added to the State. I won't define them here for brevity's sake, but it will help you understand the Store structure when it comes to initialization.

A basic rule of this pattern is that the state is changed in one way only, with a reducer function. The function that looks like this:

export function reducer(state, action) {}

It gets passed state and an action. Here are the reducer functions for the three state slices.

export function articlesreducer(state: ArticleState = InitialArticleState, action: Action) {}

export function authreducer(state: AuthState = InitialAuthState, action: Action) {}

export function preferencesreducer(state: PreferencesState = InitialPreferenceState, action: Action) {}

Here with types. As you can see, the articlesreducer doesn't get State as a parameter, but State.articles. How does that work? This is how you define your reducers.

export const reducers: ActionReducerMap<State> = {
   articles: articlesreducer,
   auth: authreducer,
   preferences: preferencesreducer
}

Then to initialize the state, in your app.module.ts file

imports: [
   StoreModule.forRoot(reducers),
]

The reducers object and the State interface properties match. When a reducer is called, the auth reducer is called with State.auth.

In the reducer function, if state is undefined it is assigned the value of the default. On initialization all reducers are called with an undefined state, initializing the state on startup.

What about that selector used in the component? Selectors are composed of a series of selectors that extract a specific property from the State.

export const getArticleState = (state: State) => state.articles;
export const getArticleList = (state: ArticleState) => state.articlelist;
export const getArticles = createSelector(getArticleState, getArticleList);

More boilerplate. Why not something like this?

export const getArticles = (state: State) => state.articles.articlelist;

Because every time any changes happen in State, the subscription in your component would fire.

This is one way of the two way data flows in the NGRX pattern. But it shows promise. A change in the state values will show up in the view. The data acquisition and handling is outside of the component. The Store structure is extensible, adding another state slice breaks nothing, making adding a feature to your app or component almost trivial.

How do you modify State? See here.
How do you break down the State into pieces that are modular?
How do you deal with api calls to get data from elsewhere? Here


For a suggestion on how to layout the files and folder structure, ngrx/example-app auth implementation





  


Разместил: Planet KDE | Дата: 04.09.2017 | Прочитано: 61 | Раздел: System & Utilities   

Рейтинг статьи

Средняя оценка: 0.00/0Средняя оценка: 0Всего голосов:0

Отлично
Хорошо Нормально Пойдёт Плохо


Смотрите также связанные темы

16.05.2011 New Articles Published for Week Ending 5/14/11
New Articles Published for Week Ending 5/14/11 VMware ACE Applying a policy update package in ACE fails with the error: Setup has detected that this ACE package requires a newer version of VMware Workstation (1038992) Date Published: 5/9/2011 VMware Converter Converting a physical or virtual machine with VMware Converter takes longer than expected (1038454) Date Published: 5/12/2011 Starting a virtual machine that was converted using VMware Converter fails with the error: STOP 0x79 MISMATCHED_HAL (1038576) Date Published: 5/11/2011 Unable to log in to a Windows virtual machine after it h...
15.10.2008 Peet’s Coffee & Tea, Inc. Chooses VMware, Inc. Virtualization Platform
Specialty Coffee and Tea Company Deploys VMware Platform to Support Its Integrated Systems and Roast- to- Order Commitment to Customers. PALO ALTO, Calif. / EMERYVILLE, Calif. – October 14, 2008 —VMware, Inc. (NYSE: VMW), the global leader in virtualization solutions from the desktop to the datacenter, today announced that Peet’s Coffee & Tea, Inc. (Nasdaq: PEET), the premier specialty coffee and tea company in the U.S., has deployed VMware Infrastructure 3 and VMware Stage Manager to create a scalable, efficient and reliable platform for enterprise resource planning (ERP), store-level invento...
15.02.2010 Top 5 Planet V12n blog posts week 06
Top 5 Planet V12n blog posts week 06 VMware PEX 2010 was great... but it did mean I was extremely busy and didn't have time to create the top-5. I just picked the 5 best reads this week. Check it out: Jason Boche - My VCDX defense experienceThe first 75 minutes is spent “defending” my design.  I’ve got about a 15 slide deck to get through and to use as reference throughout the design defense.  I’d highly recommend putting as much reference as you can in the slide deck which you can yourself refer to during the defense.  It will help illustrate design choices and jog y...
06.06.2013 New Version of QNX CAR Platform Expands Design Choices to Include Android Apps and Qt User Interfaces
"Enables automotive companies to tap into vast ecosystem of mobile developers creating Android, HTML5, OpenGL ES, and Qt appsDETROIT, Telematics Detroit Conference, June 5, 2013 QNX Software Systems Limited, a global leader in software platforms for in-car electronics, today demonstrated how the new version of its QNX CAR Platform for Infotainment will enable developers of car infotainment systems to leverage an even broader choice of mobile apps and content.The QNX CAR Platform already supports both HTML5 and OpenGL ES, the two most popular open standards for mobile app development. With the ...
31.01.2011 New Articles Published for Week ending 1/29/2011
New Articles Published for Week ending 1/29/2011 VI SDK Recommended values in the soapAction field when forming Soap Requests for vSphere API (1033447) Date Published: 1/27/2011 VMware ACE Connecting a second mouse or keyboard directly to a hosted virtual machine (1033435) Date Published: 1/24/2011 VMware Data Recovery VdrFileRestore fails to run on Linux based operating systems (1033645) Date Published: 1/27/2011 VMware ESX Cannot create an additional disk on a different datastore on ESX while restoring the virtual machine (1030790) Date Published: 1/24/2011 Booting the Red Hat Enterprise ...
17.04.2011 Accessing your business contacts
Companies often store their customer information in databases managed by customer relation management tools.
25.04.2011 New Articles Published for week ending 4/23/11
New Articles Published for week ending 4/23/11 VMware ESX Installing and upgrading VMware Tools fails with the error: An error occurred while trying to access image file /usr/lib/vmware/isoimages/linux.iso (1037405) Date Published: 4/20/2011 Viewing performance data from vSphere Client fails with a HostCtl Exception (1037671) Date Published: 4/21/2011 The Windows virtual machine with VMware Tools reports Event ID 105 in the Event Viewer tab (1037755) Date Published: 4/18/2011 Powering on a virtual machine from a suspend state or reverting to a snapshot fails (1038218) Date Published: 4/20/...
07.05.2011 Top 5 Planet V12N blog posts for week 18
Top 5 Planet V12N blog posts for week 18 The VMware community is a unique social community with lots of collaboration, and people consistently trying to help each other out.  I think this makes this social circle more unique than some other social media circles out there.  For example check out the first blog post by Jason Boche, he has offered up his own lab infrastructure and bandwidth for anyone to test the VMware View iPad client.  Very cool! A couple of people have asked me how do I select the 5 blog posts for the week.  Giving back to the community is one of the qu...
30.05.2011 New Articles Published for Week Ending 5/28/11
New Articles Published for Week Ending 5/28/11 VMware ESX Cannot enable EVC in a cluster that has IBM blades (1000545) Date Published: 5/26/2011 Reinstalling the vpxa or aam agent without losing the host record from the vCenter Server database (1031919) Date Published: 5/26/2011 Accessing the vSphere Client Help fails when using Google Chrome as the default browser (1037183) Date Published: 5/24/2011 After running diskpart.exe to extend the disk size in Windows, the partition size does not get updated (1000630) Date Published: 5/23/2011 Troubleshooting issues when creating or committing sn...
06.06.2011 New Articles Published for Week Ending 6/4/11
New Articles Published for Week Ending 6/4/11 Grails What is the authority to export Grails and Grails plugins? (2000210) Date Published: 6/3/2011 Which Grails plugins are supported by SpringSource? (2000287) Date Published: 6/3/2011 VMware Capacity Planner Improving Capacity Planner Consolidation Ratio (1000256) Date Published: 6/1/2011 VMware Converter Converting a SUSE machine fails with the error: Converter.fault.HelperVmConnectionToSourceFault (1039312) Date Published: 5/30/2011 Cannot log in to a P2V converted Windows 2000 virtual machine (2000280) Date Published: 6/3/2011 VMware...
Нет комментариев. Почему бы Вам не оставить свой?
Вы не можете отправить комментарий анонимно, пожалуйста зарегистрируйтесь.
Google Search
Google

Web irc-unix.net

Топ Новостей
1: KDE Community announces fully open source Plasma Mobile
Hot NEWS!
Просмотров - 575


2: KWallet5 can be auto-unlocked during login again
Просмотров - 514

3: Interview with Laura
Просмотров - 489

4: Use ownCloud provided Packages, then VM, then Zip, no distro packages.
Просмотров - 485

5: Plasma Components on Android: Accelerating Subsurface Mobile Development
Просмотров - 478

6: VMware Workstation 11 and kwin - hangs and hiccups (solved?)
Просмотров - 452

7: Plasma 5 Powers KaOS Productivity
Просмотров - 443

8: KWrite on Mac – Application Bundle
Просмотров - 437

9: New Year Calligra Words Sprint
Просмотров - 415

10: FOSDEM Desktops DevRoom 2016 Call for Participation
Просмотров - 412

11: digiKam 5.0.0-beta2 is released
Просмотров - 410

12: Interview with Pierre Geier
Просмотров - 401

13: back in the habit
Просмотров - 394

14: Kexi 3
Просмотров - 393

15: Amarok is slowly catching up
Просмотров - 386

Google 120X240
Ссылки

Главная | Actual Topics | Статьи | Обратная связь | Guest Book
Генерация: 0.932 сек. и 13 запросов к базе данных за 0.889 сек.
Powered by SLAED CMS © 2005-2007 SLAED. All rights reserved.