Simplify session's get function

This commit is contained in:
Tissevert 2018-12-30 23:35:39 +01:00
parent 52a6d8fc91
commit cc2079050b
3 changed files with 6 additions and 16 deletions

View File

@ -13,7 +13,7 @@ function Buttons(session) {
}; };
document.addEventListener('keydown', function(event) { document.addEventListener('keydown', function(event) {
var button = session.get('options').layout[event.key]; var button = session.get().options.layout[event.key];
if(button != undefined && mapping != undefined && mapping[button] != undefined) { if(button != undefined && mapping != undefined && mapping[button] != undefined) {
event.preventDefault(); event.preventDefault();
mapping[button](); mapping[button]();
@ -30,7 +30,7 @@ function Buttons(session) {
function assign(key, button) { function assign(key, button) {
var layoutDiff = {}; var layoutDiff = {};
var layout = session.get('options').layout; var layout = session.get().options.layout;
for(var currentKey in layout) { for(var currentKey in layout) {
if(layout[currentKey] == button) { if(layout[currentKey] == button) {
layoutDiff[currentKey] = undefined; layoutDiff[currentKey] = undefined;

View File

@ -30,18 +30,8 @@ function Session(async, messaging) {
return o; return o;
} }
function get(path, obj) { function get() {
obj = obj == undefined ? session : obj; return session;
if(Array.isArray(path)) {
if(path.length == 0) {
return obj;
} else {
var key = path.shift();
return get(path, obj[key]);
}
} else {
return obj[path];
}
} }
function save(key, value) { function save(key, value) {

View File

@ -5,7 +5,7 @@ function UI(async, buttons, cache, dom, messaging, screen, session) {
medium: 50, medium: 50,
fast: 20 fast: 20
}; };
var textSpeed = session.get('options').textSpeed; var textSpeed = session.get().options.textSpeed;
return { return {
animation: animation, animation: animation,
@ -212,7 +212,7 @@ function UI(async, buttons, cache, dom, messaging, screen, session) {
} }
function setLayout() { function setLayout() {
var layout = session.get('options').layout var layout = session.get().options.layout;
var buttonsMenu = { var buttonsMenu = {
cancel: function() {}, cancel: function() {},
entries: [], entries: [],