-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
95 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,22 @@ | ||
/* | ||
/* | ||
Erstelle ein Admin Modul, dass | ||
- eine Klasse Person | ||
- eine Klasse Person | ||
- und eine Klasse Store | ||
zur Verfügung stellt. | ||
Interfaces: | ||
So sollen die Klassen aussehen: | ||
Person(name, vorname) | ||
Store(items) | ||
- add(item) | ||
- remove(item) | ||
- findAll(item=>boolean) | ||
// items kann z.B. ein Array von Personen sein | ||
- add(item) | ||
- remove(item) | ||
- findAll(item => boolean) | ||
// das bedeutet: die Methode findAll erwartet als Argument eine Funktion, | ||
welche als Argument ein Item entgegen nimmt und ein Boolean retourniert | ||
Schreibe ein Programm (client.js), welches einen Store verwendet um Personen darin zu speichern, löschen, suchen. | ||
*/ | ||
Schreibe ein Programm client.js, welches einen Store verwendet um Personen darin | ||
zu speichern, löschen, suchen. | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
'use strict' | ||
|
||
export {default as Person} from './person' | ||
export {default as Store} from './store' | ||
export {Person} from './person.js' | ||
export {Store} from './store.js' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Store Client - Modules</title> | ||
<script type="module" src="client.js"></script> | ||
</head> | ||
<body> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
'use strict' | ||
export default class { | ||
export class Person { | ||
constructor(name, vorname){ | ||
this.name = name | ||
this.vorname = vorname | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,29 @@ | ||
'use strict' | ||
export default class { | ||
export class Store { | ||
constructor(items){ | ||
this.items = items || [] | ||
} | ||
|
||
add(item){ | ||
this.items.push(item) | ||
} | ||
|
||
remove(item){ | ||
let itemIdx = this.items.indexOf(item) | ||
if(itemIdx > -1){ | ||
this.items.splice(itemIdx, 1) | ||
} | ||
} | ||
|
||
findAll(matcher){ | ||
return this.items.filter(matcher) | ||
const matches = [] | ||
for(let item of this.items){ | ||
if(matcher(item)){ | ||
matches.push(item) | ||
} | ||
} | ||
return matches | ||
|
||
// funktionaler ansatz | ||
// return this.items.filter(matcher) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// 'use strict' // optional, weil im Browser via <script type="module" geladen | ||
|
||
// import default | ||
import Logger from './logger.module.js' | ||
// oder als named import | ||
//import {default as Logger} from './logger.module.js' | ||
// import explicit | ||
import {PI as pii} from './logger.module.js' | ||
import {PI} from './logger.module.js' | ||
|
||
let l = new Logger(console.log) | ||
l.warn('hi') | ||
l.log('du') | ||
l.log([pii, PI, Logger.PI]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Modules</title> | ||
<script type="module" src="app.js"></script> | ||
</head> | ||
<body> | ||
|
||
</body> | ||
</html> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// 'use strict' // optional, weil im Browser via <script type="module" geladen | ||
|
||
// nicht exportiert => kein Zugriff von aussen | ||
function getFormattedDate(){ | ||
return new Date().toISOString() | ||
} | ||
|
||
export default class { | ||
constructor(writer){ | ||
this.writer = writer | ||
} | ||
warn(msg){ | ||
this.writer('WARNING ' + getFormattedDate() + '\n' + msg) | ||
} | ||
log(msg){ | ||
this.writer('LOG ' + getFormattedDate() + '\n' + msg) | ||
} | ||
} | ||
|
||
export const PI=3.141592653 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters