Skip to content

Commit 6da1f3d

Browse files
committed
Create separate class for NoteManager, remove unused packages
1 parent d2fa6b8 commit 6da1f3d

File tree

11 files changed

+67
-1712
lines changed

11 files changed

+67
-1712
lines changed

package-lock.json

Lines changed: 1 addition & 1538 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@
1717
"babel-minify-webpack-plugin": "^0.3.1",
1818
"clean-webpack-plugin": "^1.0.0",
1919
"css-loader": "^2.1.0",
20-
"file-loader": "^3.0.1",
2120
"html-loader": "^0.5.5",
2221
"html-webpack-plugin": "^4.0.0-beta.5",
23-
"image-webpack-loader": "^4.6.0",
2422
"mini-css-extract-plugin": "^0.5.0",
2523
"node-sass": "^4.11.0",
2624
"optimize-css-assets-webpack-plugin": "^5.0.1",
@@ -30,8 +28,5 @@
3028
"webpack-cli": "^3.2.0",
3129
"webpack-dev-server": "^3.1.14",
3230
"tar": ">=2.2.2"
33-
},
34-
"dependencies": {
35-
"bootstrap": "^4.3.1"
3631
}
3732
}

src/Note.js

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,4 @@
1-
export class NoteManager {
2-
constructor({el, notes}) {
3-
this.el = el;
4-
this.notesEl = null;
5-
this.notes = notes.map(note => new Note(note, this));
6-
7-
this.onNoteChange = () => {};
8-
this.createNotesWrapper();
9-
this.renderNotes();
10-
}
11-
12-
addNote(note) {
13-
this.notes.push(new Note(note, this));
14-
this.renderNotes();
15-
}
16-
17-
prependNote(note) {
18-
this.notes.unshift(new Note(note, this));
19-
this.renderNotes();
20-
}
21-
22-
removeNote(note) {
23-
this.notes.splice(this.notes.indexOf(note), 1);
24-
this.renderNotes();
25-
}
26-
27-
createNotesWrapper(){
28-
this.notesEl = document.createElement('div');
29-
this.notesEl.className = 'tc-notes';
30-
this.el.appendChild(this.notesEl);
31-
}
32-
33-
renderNotes() {
34-
this.notesEl.innerHTML = '';
35-
this.notes.forEach(note => this.renderNote(note));
36-
}
37-
38-
renderNote(note) {
39-
this.notesEl.appendChild(note.createNoteEl())
40-
}
41-
}
42-
43-
export class Note {
1+
export default class Note {
442

453
constructor({title, body}, noteManager) {
464
this.el = null;

src/NoteManager.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import Note from './Note';
2+
3+
export default class NoteManager {
4+
constructor({el, notes}) {
5+
this.el = el;
6+
this.notesEl = null;
7+
this.notes = notes.map(note => new Note(note, this));
8+
9+
this.onNoteChange = () => {
10+
};
11+
this.createNotesWrapper();
12+
this.renderNotes();
13+
}
14+
15+
addNote(note) {
16+
this.notes.push(new Note(note, this));
17+
this.renderNotes();
18+
}
19+
20+
prependNote(note) {
21+
this.notes.unshift(new Note(note, this));
22+
this.renderNotes();
23+
}
24+
25+
removeNote(note) {
26+
this.notes.splice(this.notes.indexOf(note), 1);
27+
this.renderNotes();
28+
}
29+
30+
createNotesWrapper() {
31+
this.notesEl = document.createElement('div');
32+
this.notesEl.className = 'tc-notes';
33+
this.el.appendChild(this.notesEl);
34+
}
35+
36+
renderNotes() {
37+
this.notesEl.innerHTML = '';
38+
this.notes.forEach(note => this.renderNote(note));
39+
}
40+
41+
renderNote(note) {
42+
this.notesEl.appendChild(note.createNoteEl())
43+
}
44+
}

src/app.js

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,40 @@
11
import './scss/style.scss';
2-
import {Note, NoteManager} from './Note';
2+
import NoteManager from './NoteManager';
33

44
const noteManager = new NoteManager({
55
el: document.getElementById('notesWrapper'),
66
notes: [
77
{
8-
title: 'This is a demo note',
9-
body: 'Lorem ipsum dolor sit amet consectetur adipisicing elit. Modi corrupti officiis alias tenetur, tenetur iste maxime laudantium?'
8+
title: 'sunt aut facere repellat',
9+
body: 'uia et suscipit suscipit recusandae consequuntur expedita et cum reprehenderit molestiae ut ut quas totam nostrum rerum est autem sunt rem eveniet architecto'
1010
},
1111
{
12-
title: 'This is a demo note',
13-
body: 'Lorem ipsum dolor sit amet consectetur adipisicing elit. Modi corrupti officiis alias tenetur, tenetur iste maxime laudantium?'
12+
title: 'qui est esse',
13+
body: 'est rerum tempore vitae<br>nsequi sint nihil reprehenderit dolor beatae ea dolores neque <br>fugiat blanditiis voluptate porro vel nihil molestiae ut reiciendis<br>qui aperiam non debitis possimus qui neque nisi nulla'
1414
},
1515
{
16-
title: 'This is a demo note',
17-
body: 'Lorem ipsum dolor sit amet consectetur adipisicing elit. Modi corrupti officiis alias tenetur, tenetur iste maxime laudantium?'
16+
title: 'nesciunt quas odio',
17+
body: 'repudiandae veniam quaerat sunt sed alias aut fugiat sit autem sed est'
1818
},
1919
{
2020
title: 'This is a demo note',
2121
body: 'Lorem ipsum dolor sit amet consectetur adipisicing elit. Modi corrupti officiis alias tenetur, tenetur iste maxime laudantium?'
2222
},
23+
{
24+
title: 'qui est esse',
25+
body: 'est rerum tempore vitae<br>nsequi sint nihil reprehenderit dolor beatae ea dolores neque <br>fugiat blanditiis voluptate porro vel nihil molestiae ut reiciendis<br>qui aperiam non debitis possimus qui neque nisi nulla'
26+
},
2327
]
2428
});
2529

30+
noteManager.onNoteAdd = (note) => {
31+
console.log("Note added", note);
32+
};
2633
noteManager.onNoteChange = (note) => {
27-
console.log(note);
34+
console.log("Note changed", note);
35+
};
36+
noteManager.onNoteRemove = (note) => {
37+
console.log("Note removed ", note);
2838
};
2939

3040
const newNoteBtn = document.querySelector('.new-note-btn');

src/scss/app/main.scss

Whitespace-only changes.

src/scss/style.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ body {
5353
.tc-note-header {
5454
padding: 10px 16px 0;
5555

56-
.tc-note-add,
5756
.tc-note-close {
5857
display: inline-block;
5958
width: 24px;
@@ -85,6 +84,7 @@ body {
8584
.tc-note-title {
8685
font-size: 24px;
8786
padding: 10px 16px;
87+
font-weight: bold;
8888
}
8989

9090
.tc-note-body {

src/scss/vendor/bootstrap.scss

Lines changed: 0 additions & 39 deletions
This file was deleted.

src/scss/vendor/variables.scss

Lines changed: 0 additions & 1 deletion
This file was deleted.

webpack.config.js

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ module.exports = function(){
2727
},
2828
plugins: [
2929
new HtmlWebpackPlugin({
30-
title: 'Webpack starter project',
3130
template: path.resolve('./src/index.html')
3231
}),
3332
new webpack.HotModuleReplacementPlugin()
@@ -52,30 +51,6 @@ module.exports = function(){
5251
}
5352
}
5453
},
55-
{
56-
test: /\.(pdf|doc|docx|xls|xlsx|txt|csv|tsv)$/,
57-
use: [
58-
{
59-
loader: "file-loader",
60-
options: {
61-
outputPath: './files',
62-
name: "[name].[ext]",
63-
},
64-
}
65-
]
66-
},
67-
{
68-
test: /\.(jpg|jpeg|gif|png|svg|webp)$/,
69-
use: [
70-
{
71-
loader: "file-loader",
72-
options: {
73-
outputPath: './images',
74-
name: "[name].[ext]",
75-
},
76-
},
77-
]
78-
},
7954
{
8055
test: /\.(woff(2)?|ttf|otf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/,
8156
use: [
@@ -100,4 +75,4 @@ module.exports = function(){
10075
]
10176
}
10277
};
103-
}
78+
}

0 commit comments

Comments
 (0)