-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from PavelUd/module7-task1
- Loading branch information
Showing
20 changed files
with
534 additions
and
91 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
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
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 |
---|---|---|
|
@@ -11,3 +11,5 @@ export const getRandomPoint = (type, destinationId, offerIds) => ({ | |
offers: offerIds, | ||
type | ||
}); | ||
|
||
|
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 @@ | ||
import Observable from '../framework/observable.js'; | ||
import {FILTER_TYPES} from '../const.js'; | ||
|
||
export default class FilterModel extends Observable { | ||
#filter = FILTER_TYPES.EVERYTHING; | ||
get() { | ||
return this.#filter; | ||
} | ||
|
||
set(updteType, update){ | ||
this.#filter = update; | ||
this._notify(updteType, update); | ||
} | ||
} |
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,10 +1,39 @@ | ||
export default class PointsModel { | ||
import Observable from '../framework/observable'; | ||
import { updateItem } from '../mock/util.js'; | ||
|
||
export default class PointsModel extends Observable { | ||
#points; | ||
#service; | ||
|
||
constructor(service) { | ||
this.service = service; | ||
this.points = this.service.getPoints(); | ||
super(); | ||
this.#service = service; | ||
this.#points = this.#service.getPoints(); | ||
} | ||
|
||
getAll() { | ||
return this.points; | ||
return this.#points; | ||
} | ||
|
||
getById(id) { | ||
return this.#points.find((point) => point.id === id); | ||
} | ||
|
||
add(type, point) { | ||
const newPoint = this.#service.addPoint(point); | ||
this.#points.push(newPoint); | ||
this._notify(type, newPoint); | ||
} | ||
|
||
update(type, point) { | ||
const updatedPoint = this.#service.updatePoint(point); | ||
this.#points = updateItem(this.#points, updatedPoint); | ||
this._notify(type, updatedPoint); | ||
} | ||
|
||
delete(type, deletedPoint) { | ||
this.#service.deletePoint(deletedPoint); | ||
this.#points = this.#points.filter((point) => point.id !== deletedPoint.id); | ||
this._notify(type); | ||
} | ||
} |
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
Oops, something went wrong.