Skip to content
This repository has been archived by the owner on Oct 18, 2021. It is now read-only.

Commit

Permalink
Merge pull request #21 from frontsideair/map-api
Browse files Browse the repository at this point in the history
Move from Object api to Map api
  • Loading branch information
frontsideair authored Dec 6, 2019
2 parents 171c4d2 + a3840cb commit 65450df
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const app = express();
app.use(middleware(tgl));

app.get("/", (req, res) => {
const universal = req.tgl.universal;
const universal = req.tgl.get("universal");
res.send(universal ? "Hello, universe!" : "Hello, world!");
});

Expand Down
2 changes: 1 addition & 1 deletion example/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const app = express();
app.use(middleware(tgl));

app.get("/", (req, res) => {
const universal = req.tgl.universal;
const universal = req.tgl.get("universal");
res.send(universal ? "Hello, universe!" : "Hello, world!");
});

Expand Down
6 changes: 4 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ class Tgl {
}

get(key) {
return this._cache[key];
return this._cache.hasOwnProperty(key)
? this._cache[key]
: this.toggles.find(toggle => toggle.name === key).defaultValue;
}
}

function middleware(tgl) {
return (req, res, next) => {
req.tgl = tgl._cache;
req.tgl = tgl;
next();
};
}
Expand Down
2 changes: 1 addition & 1 deletion lib/view.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function li({ name, defaultValue, description }, value = defaultValue) {
function li({ name, defaultValue, description }, value) {
const checked = value ? "checked" : "";
return `<li><label><input type="checkbox" name="${name}" id="${name}" ${checked}> ${description} (${name})</label></li>`;
}
Expand Down

0 comments on commit 65450df

Please sign in to comment.