Skip to content

Commit

Permalink
feat(sample): provide an example SPA
Browse files Browse the repository at this point in the history
provide SPA example in docs/mvc

close: #1
  • Loading branch information
rondinif committed May 19, 2019
1 parent 480beb5 commit e621c5d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 33 deletions.
9 changes: 2 additions & 7 deletions esm/config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
try {
import dotenv from 'dotenv-flow';
dotenv.config();
}
catch(err) {
// document.getElementById("demo").innerHTML = err.message;
}
import dotenv from 'dotenv-flow';

dotenv.config();
/*
usage in programs:
import { config } from './lib/config.mjs';
Expand Down
22 changes: 8 additions & 14 deletions esm/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
const isNode = ( typeof window === 'undefined')
/*
if (isNode) {
try {
import { config } from '../esm/config.js';
import { logconfig } from '../esm/logconfig.js';
} catch (e) {
console.log("?");
}
}
*/
import { Log } from '../esm/log.js';
import { config } from '../esm/config';
import { logconfig } from '../esm/logconfig';
import { Log } from '../esm/log';

// DIP: export Higher-order function factories : each of them returns a function as its result.

Expand Down Expand Up @@ -240,7 +231,7 @@ function getPromiseOfPlantResolvedByOpendataByName({ ff, ffSparql, config, log }
log.warn(`specieArticle #ND [${e.message}]`);
}
} catch (eo) {
log.error(eo.message); // UNCOVERED ( intentionally left for DIFENSIVE PROGRAMMING )
log.error(eo.message); // UNCOVERED ( intentionally left for DEFENSIVE PROGRAMMING )
}

entities[i] = {
Expand All @@ -262,7 +253,7 @@ function getPromiseOfPlantResolvedByOpendataByName({ ff, ffSparql, config, log }
name: responseOfPlantsSearchedByAnyName.name,
plants: entities
});
})().catch(e => log.debug("loopWDEntities Caught Error: " + e)); // UNCOVERED ( intentionally left for DIFENSIVE PROGRAMMING )
})().catch(e => log.debug("loopWDEntities Caught Error: " + e)); // UNCOVERED ( intentionally left for DEFENSIVE PROGRAMMING )
}); // closing res.then
});
}
Expand All @@ -282,9 +273,12 @@ class Phyto {
* @param {Function} logger
*/
constructor(fetch, config$1, log) {
// let effectiveConfig = (typeof config == 'undefined') ? defaultConfig : config;
// let effectiveLog = (typeof log == 'undefined') ? new DefaultLog(logconfig) : log;
let effectiveConfig = (typeof config$1 == 'undefined') ? (typeof config == undefined) ? {isUnderTest: () => false } : config : config$1;
let effectiveLog = (typeof log == 'undefined') ? new Log((typeof logconfig == undefined) ? {isLogVerbose: () => false, isLogSilent: () => true } : logconfig) : log;


const _ff = makeGetPromiseOfWikiDataApiResults(fetch, effectiveLog);
const _ffSparql = makeGetPromiseOfSparqlResults(fetch, effectiveLog);

Expand Down
15 changes: 9 additions & 6 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import { config as defaultConfig } from './config/config';
import { logconfig } from './config/logconfig';
import { Log as DefaultLog } from './log/log';
*/
import { config as defaultConfig } from '../esm/config.js'
import { logconfig } from '../esm/logconfig.js'
import { Log as DefaultLog } from '../esm/log.js'
import { config } from '../esm/config'
import { logconfig } from '../esm/logconfig'
import { Log } from '../esm/log'

// https://humanwhocodes.com/blog/2019/01/stop-using-default-exports-javascript-module/
/**
Expand All @@ -26,9 +26,12 @@ export class Phyto {
* @param {Function} config
* @param {Function} logger
*/
constructor(fetch, config, log) {
let effectiveConfig = (typeof config == 'undefined') ? defaultConfig : config;
let effectiveLog = (typeof log == 'undefined') ? new DefaultLog(logconfig) : log;
constructor(fetch, config$1, log) {
// let effectiveConfig = (typeof config == 'undefined') ? defaultConfig : config;
// let effectiveLog = (typeof log == 'undefined') ? new DefaultLog(logconfig) : log;
let effectiveConfig = (typeof config$1 == 'undefined') ? (typeof config == undefined) ? {isUnderTest: () => false } : config : config$1;
let effectiveLog = (typeof log == 'undefined') ? new Log((typeof logconfig == undefined) ? {isLogVerbose: () => false, isLogSilent: () => true } : logconfig) : log;


const _ff = makeGetPromiseOfWikiDataApiResults(fetch, effectiveLog);
const _ffSparql = makeGetPromiseOfSparqlResults(fetch, effectiveLog);
Expand Down
15 changes: 9 additions & 6 deletions umd/phyto.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('./config'), require('./logconfig'), require('./log')) :
typeof define === 'function' && define.amd ? define(['exports', './config', './logconfig', './log'], factory) :
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('../esm/config'), require('../esm/logconfig'), require('../esm/log')) :
typeof define === 'function' && define.amd ? define(['exports', '../esm/config', '../esm/logconfig', '../esm/log'], factory) :
(global = global || self, factory(global.phyto = {}, global.config, global.logconfig, global.log));
}(this, function (exports, config, logconfig, log) { 'use strict';

Expand Down Expand Up @@ -233,7 +233,7 @@
log.warn(`specieArticle #ND [${e.message}]`);
}
} catch (eo) {
log.error(eo.message); // UNCOVERED ( intentionally left for DIFENSIVE PROGRAMMING )
log.error(eo.message); // UNCOVERED ( intentionally left for DEFENSIVE PROGRAMMING )
}

entities[i] = {
Expand All @@ -255,7 +255,7 @@
name: responseOfPlantsSearchedByAnyName.name,
plants: entities
});
})().catch(e => log.debug("loopWDEntities Caught Error: " + e)); // UNCOVERED ( intentionally left for DIFENSIVE PROGRAMMING )
})().catch(e => log.debug("loopWDEntities Caught Error: " + e)); // UNCOVERED ( intentionally left for DEFENSIVE PROGRAMMING )
}); // closing res.then
});
}
Expand All @@ -275,8 +275,11 @@
* @param {Function} logger
*/
constructor(fetch, config$1, log$1) {
let effectiveConfig = (typeof config$1 == 'undefined') ? config.config : config$1;
let effectiveLog = (typeof log$1 == 'undefined') ? new log.Log(logconfig.logconfig) : log$1;
// let effectiveConfig = (typeof config == 'undefined') ? defaultConfig : config;
// let effectiveLog = (typeof log == 'undefined') ? new DefaultLog(logconfig) : log;
let effectiveConfig = (typeof config$1 == 'undefined') ? (typeof config.config == undefined) ? {isUnderTest: () => false } : config.config : config$1;
let effectiveLog = (typeof log$1 == 'undefined') ? new log.Log((typeof logconfig.logconfig == undefined) ? {isLogVerbose: () => false, isLogSilent: () => true } : logconfig.logconfig) : log$1;


const _ff = makeGetPromiseOfWikiDataApiResults(fetch, effectiveLog);
const _ffSparql = makeGetPromiseOfSparqlResults(fetch, effectiveLog);
Expand Down

0 comments on commit e621c5d

Please sign in to comment.