Re-engineered FieldContainer to extend successfully array with its method;

Overridden splice, push and pop methods and length prop for FieldsContainer;
Renamed FieldsContainer to FieldsArray (also file);
This commit is contained in:
Alexander Cerutti
2019-03-29 23:52:34 +01:00
parent 7b5a1e0a1e
commit 7c2540a93d
3 changed files with 78 additions and 88 deletions

View File

@@ -14,7 +14,7 @@ const loadDebug = debug("passkit:load");
const schema = require("./schema");
const formatMessage = require("./messages");
const FieldsContainer = require("./fields");
const FieldsArray = require("./fieldsArray");
const readdir = promisify(fs.readdir);
const readFile = promisify(fs.readFile);
@@ -37,7 +37,7 @@ class Pass {
this._fields = ["primaryFields", "secondaryFields", "auxiliaryFields", "backFields", "headerFields"];
this._fields.forEach(a => this[a] = new FieldsContainer());
this._fields.forEach(a => this[a] = new FieldsArray());
this._transitType = "";
// Assigning model and _props to this
@@ -212,7 +212,7 @@ class Pass {
archive.pipe(passStream);
FieldsContainer.emptyUnique();
FieldsArray.emptyUnique();
return archive.finalize().then(() => passStream);
});
@@ -633,11 +633,11 @@ class Pass {
}
this._fields.forEach(area => {
if (this[area].fields.length) {
if (this[area].length) {
if (this.shouldOverwrite) {
passFile[this.type][area] = this[area].fields;
passFile[this.type][area] = [...this[area]];
} else {
passFile[this.type][area].push(...this[area].fields);
passFile[this.type][area].push(...this[area]);
}
}
});