Author: Ahsan Ayaz
This project is created for the 3rd meetup of ngPakistan and was generated with Angular CLI version 1.0.0
The app is built on top the basic version of Angular4Rockstar Chat project with the inclusion of @ngrx/store usage.
There're two simple pages:
- Landing Page
- Chat Page (home)
Landing page is a simple page with link to Chat Page.
Chat Page has the following heirarchy of components:
home (chat page)
-- ar-chat (chat component)
---- ar-chat-messages (chat messages list)
---- ar-write-message (component to write and send a new message)
With the use of @ngrx/store, we have eliminated the component interaction using @Input
and @Output
with EventEmmitter
of course.
-
The
ar-chat
component is the parent andar-chat-messages
andar-write-message
are the children. -
The
ar-chat
component loads the initial messages usingloadMessages
method utilizingchatService.getMessages()
. Then dispatches the actionLOAD_MESSAGES
. This sets theState
ofmessages
in@ngrx/store
i.e. loads the message into state. -
The
ar-chat-messages
which displays messages, loads the messages onngOnInit
and subscribes to it using themessages$
model which is assigned anObservable
from the@ngrx/store
. Therefore the messages are displayed in the component. -
The
ar-chat-messages
component also contains the functionality to remove messages. When the delete button is triggered, the component dispatchesREMOVE_MESSAGE
event which updates the state ofmessages
refreshing the view with the remaining messages. -
The
ar-write-message
dispatches the eventADD_MESSAGE
which updates the state in the store. As a result, thear-chat-messages
component gets itsmessages$
model updated since it was subscribed to the@ngrx/store
Run ng serve
for a dev server. Navigate to http://localhost:4200/
. The app will automatically reload if you change any of the source files.
Used ngx-bootstrap
for mainly the bootstrap styles. Didn't use any component yet.
For testing, I also installed karma-spec-reporter
via npm so we can see the specs running in the consoles.
Run ng test
to execute the unit tests via Karma.
The unit test is written for chat.component
mainly. Can be found under app/components/chat/chat.component.spec.ts
Run ng e2e
to execute the end-to-end tests via Protractor.
The e2e test is written for the chat component of course. The file is at e2e/chats/chats.e2e-spec.ts
Editor: VS Code