-
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 #265 from NicDoesCode/219-optimise-getting-project…
…s-from-local-storage #219 - Optimise getting projects from local storage
- Loading branch information
Showing
13 changed files
with
678 additions
and
67 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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import ProjectEntry from "../models/projectEntry.js"; | ||
|
||
export default class ProjectEntryFactory { | ||
|
||
|
||
/** | ||
* Creates a new instance of the project entry class. | ||
* @param {ProjectEntryInitialValues} values - Initial values for the project entry. | ||
*/ | ||
static create(values) { | ||
return new ProjectEntry(values.id, values.title, values.systemType, values.dateLastModified); | ||
} | ||
|
||
|
||
} | ||
|
||
/** | ||
* @typedef {Object} ProjectEntryInitialValues | ||
* @property {string?} id - Unique ID of the new project, if not supplied one will be created. | ||
* @property {string?} title - Title, if not supplied one will be created. | ||
* @property {string?} systemType - Type of system targetted, either 'smsgg', 'gb' or 'nes', default is 'smsgg'. | ||
* @property {Date|number} dateLastModified - Date of last modification for the project. | ||
* @exports | ||
*/ |
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,93 @@ | ||
import GeneralUtil from "../util/generalUtil.js"; | ||
|
||
/** | ||
* Represents basic information about a project. | ||
*/ | ||
export default class ProjectEntry { | ||
|
||
|
||
/** Gets or sets the project id. */ | ||
get id() { | ||
return this.#id; | ||
} | ||
set id(value) { | ||
this.#id = value; | ||
} | ||
|
||
/** Gets or sets the project title. */ | ||
get title() { | ||
return this.#title; | ||
} | ||
set title(value) { | ||
this.#title = value; | ||
} | ||
|
||
/** Gets or sets the system type (either 'smsgg' or 'gb'). */ | ||
get systemType() { | ||
return this.#systemType; | ||
} | ||
set systemType(value) { | ||
this.#systemType = value; | ||
} | ||
|
||
/** Gets or sets the date that this project was last modified. */ | ||
get dateLastModified() { | ||
return this.#dateLastModified; | ||
} | ||
set dateLastModified(value) { | ||
this.#dateLastModified = value; | ||
} | ||
|
||
|
||
/** @type {string} */ | ||
#id = null; | ||
/** @type {string} */ | ||
#title; | ||
/** @type {string} */ | ||
#systemType; | ||
/** @type {Date} */ | ||
#dateLastModified; | ||
|
||
|
||
/** | ||
* Creates a new instance of the project entry class. | ||
* @param {string?} id - ID of the project. | ||
* @param {string?} title - Title, if not supplied one will be created. | ||
* @param {string?} systemType - Type of system targetted, either 'smsgg', 'gb' or 'nes', default is 'smsgg'. | ||
* @param {Date|number|null} dateLastModified - Date that the project was last modified. | ||
*/ | ||
constructor(id, title, systemType, dateLastModified) { | ||
|
||
if (typeof id !== 'undefined' && id !== null && id.length > 0) { | ||
this.#id = id; | ||
} else { | ||
this.id = GeneralUtil.generateRandomString(16); | ||
} | ||
|
||
if (typeof title !== 'undefined' && title !== null) { | ||
this.title = title; | ||
} else { | ||
this.title = 'New project'; | ||
} | ||
|
||
if (typeof systemType !== 'undefined' && systemType !== null) { | ||
switch (systemType) { | ||
case 'gb': this.systemType = 'gb'; break; | ||
case 'nes': this.systemType = 'nes'; break; | ||
case 'smsgg': default: this.systemType = 'smsgg'; break; | ||
} | ||
} else { | ||
this.systemType = 'smsgg'; | ||
} | ||
|
||
if (dateLastModified instanceof Date) { | ||
this.#dateLastModified = dateLastModified; | ||
} else if (typeof dateLastModified === 'number') { | ||
this.#dateLastModified = new Date(dateLastModified); | ||
} else { | ||
this.#dateLastModified = new Date(); | ||
} | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.