Skip to content

Commit

Permalink
add: blueprints
Browse files Browse the repository at this point in the history
  • Loading branch information
benchambule committed Aug 24, 2024
1 parent 621791f commit d0296be
Showing 1 changed file with 84 additions and 0 deletions.
84 changes: 84 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export {

Message,
Lottus,
Blueprint,

create_options_processor,
create_input_processor,
Expand All @@ -31,6 +32,72 @@ class Message {
}


class Blueprint {
__infos = Object.create(null);
__forms = Object.create(null);

info(location, result){
if(typeof location !== "string" || !location){
throw new Error("location must be a non-empty string");
}

if(typeof result === "function" || result instanceof Message){
this.__infos[location] = result;
return this;
}

throw new Error("func must be a function or Message");
}

get(location, result){
this.info(location, result);

return this;
}

information(location, result){
this.info(location, result);

return this;
}

form(location, result){
if(typeof location !== "string" || !location){
throw new Error("location must be a non-empty string");
}

if(typeof result === "function" || result instanceof Message){
this.__forms[location] = result;
return this;
}

throw new Error("result must be a function or Message");
}

post(location, result){
this.form(location, result);

return this;
}

at(location, info, proc){
this.info(location, info);
this.form(location, proc);

return this;
}

get_forms(){
return this.__forms;
}

get_infos(){
console.log("get_infos");
return this.__infos;
}
}


class Lottus {
__infos = Object.create(null);
__forms = Object.create(null);
Expand Down Expand Up @@ -259,6 +326,23 @@ class Lottus {

return result;
}


/**
*
* @param {Blueprint} bp
*/
addBlueprint(bp){
if(!(bp instanceof Blueprint)){
throw new Error("bp must be of type Blueprint");
}

this.__infos = {...this.__infos, ...bp.get_infos()};
this.__forms = {...this.__forms, ...bp.get_forms()};

console.log(this.__infos);
console.log(this.__forms);
}
}


Expand Down

0 comments on commit d0296be

Please sign in to comment.