The app utilized 2 classes: Post and SocialMediaApp.
Post is responsible for creating instances of posts.
Posts have properties: name/author, title, date, text, comments, and likes.
Posts have methods for:
- liking a post,
- disliking a post,
- adding a new comment,
- editing the post,
- editing a comment,
- deleting a comment,
- displaying the post.
SocialMediaApp initialized my social media app object.
a SM app has properties: name, posts (array)
a SM app has methods:
- add new post — creates a new Post instance by calling the constructor method of the Post class, gives it a unique ID and pushes to the posts array
- delete a post — removes a post by id
- display all posts — calls the method responsible for displaying the post data on every post stored in the posts array
! See the call-stack
branch for live examples
new SocialMediaApp();
returns an instance of a social app. e.g.
const veryUniqueApp = new SocialMediaApp();
veryUniqueApp.addNewPost(obj);
returns an instance of a post and adds it to the array of posts stored by the created social app object.
Its argument, obj
, has the following format:
{
className: Post,
name: 'Some Name',
title: 'Some Title',
text: 'Some Text'
}
For example:
const post1 = veryUniqueApp.addNewPost({className: Post, name: 'Jill', title: 'Let me explain JS expressions', text: 'A JS expression is a piece of code that always evaluates to something, resolves in a single value...'});
post1.likePost();
— like the post
post1.dislikePost();
— dislike the post
Example:
post1.updatePost({title: 'JS expressions'});
Add a new comment (examples):
post1.addNewComment({name: 'Marc', text: 'Brilliant!'});
post1.addNewComment({name: 'Jed', text: 'trololo'});
Edit a comment by its ID (IDs are automatically generated when being added to a post and can be retrieved by logging the .comments
property on the post instance):
post1.updateComment({id: 1, text: 'LOL'});
Delete a comment by ID:
post1.deleteComment({id: 1});
Display a single post (example):
post1.displayPost();
Display all posts (example):
veryUniqueApp.displayPosts();
Example:
veryUniqueApp.deletePost({id: 0});