Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: only instantiate Genera once when loading #17

Merged
merged 3 commits into from
Dec 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion data/taxa.csv
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ Eremalche exilis,,N,24546,3045,58199,White Mallow
Eremalche parryi subsp. parryi,,N,50324,3049,58936,Parry's Mallow
Eremothera boothii subsp. decorticans,shredding evening-primrose,N,89263,11654,79836,Desert Shredding Primrose
Eriastrum abramsii,,N,24587,3052,57203,Abrams' Woollystar
Eriastrum ertterae,Lime Ridge eriastrum,N,99214,13079,473592,Lime Ridge Eriastrum,,,,,3786,1B.1,CC,,S1,G1
Eriastrum ertterae,Lime Ridge eriastrum,N,99214,13079,473592,Lime Ridge Eriastrum,,,,,3786,1B.1,CE,,S1,G1
Eriastrum pluriflorum subsp. pluriflorum,,N,50337,11660,79842,Many-flowered Eriastrum
Eriastrum pluriflorum,many-flowered eriastrum,N,24595,3065,58239,Many Flowered Eriastrum
Ericameria arborescens,golden-fleece,N,2583,3071,63924,Golden Fleece
Expand Down
2 changes: 1 addition & 1 deletion lib/genera.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class Genus {

getTaxa() {
return this.#data.taxa.sort((a, b) =>
a.getName().localeCompare(b.getName())
a.getName().localeCompare(b.getName()),
);
}
}
Expand Down
8 changes: 4 additions & 4 deletions lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ export class Config {
prefix: string,
name: string,
subcategory?: string,
defaultValue?: string
defaultValue?: string,
): string;
getCountyCodes(): string[];
getLabel(name: string, dflt: string): string;
}

export class CSV {
static parseFile(dir: string, fileName: string): void;
static parseFile(dir: string, fileName: string): Record<string, string>[];
}

export class ErrorLog {
Expand All @@ -31,7 +31,7 @@ export class Files {
static exists(fileName: string): boolean;
static fetch(
url: string | URL,
targetFileName: string | undefined
targetFileName: string | undefined,
): Promise<Headers>;
static mkdir(dir: string): void;
static rmDir(dir: string): void;
Expand All @@ -50,7 +50,7 @@ export class Taxa {
showFlowerErrors: boolean,
taxonFactory?: (td: TaxonData, g: Genera) => Taxon,
extraTaxa?: TaxonData[],
extraSynonyms?: SynonymData[]
extraSynonyms?: SynonymData[],
);
getTaxon(name: string): Taxon;
getTaxonList(): Taxon[];
Expand Down
7 changes: 5 additions & 2 deletions lib/taxa.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,21 @@ class Taxa {
const dataDir = Config.getPackageDir() + "/data";

this.#families = new Families();
const genera = new Genera(this.#families);

const taxaCSV = new TaxaCSV(dataDir);
this.#loadTaxa(
taxaCSV.getTaxa(),
inclusionList,
taxonFactory,
genera,
showFlowerErrors,
);
this.#loadTaxa(
extraTaxa,
inclusionList,
taxonFactory,
genera,
showFlowerErrors,
);

Expand Down Expand Up @@ -184,10 +187,10 @@ class Taxa {
* @param {TaxonData[]} taxaCSV
* @param {Object<string,TaxonData>|true} inclusionList
* @param {function(TaxonData,Genera):Taxon} taxonFactory
* @param {Genera} genera
* @param {boolean} showFlowerErrors
*/
#loadTaxa(taxaCSV, inclusionList, taxonFactory, showFlowerErrors) {
const genera = new Genera(this.#families);
#loadTaxa(taxaCSV, inclusionList, taxonFactory, genera, showFlowerErrors) {
for (const row of taxaCSV) {
const name = row["taxon_name"];

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ca-plant-list/ca-plant-list",
"version": "0.4.12",
"version": "0.4.13",
"description": "Tools to create Jekyll files for a website listing plants in an area of California.",
"license": "MIT",
"repository": {
Expand Down
Loading