mirror of
https://github.com/chaoticbackup/chaoticbackup.github.io.git
synced 2026-03-21 17:24:14 -05:00
[add] lokijs in-memory database
This commit is contained in:
parent
0b3b39d990
commit
2fcf3557b4
|
|
@ -1,10 +1,11 @@
|
||||||
{
|
{
|
||||||
"folders":
|
"folders":
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"path": "."
|
"path": ".",
|
||||||
}
|
"folder_exclude_patterns": ["build", "node_modules"]
|
||||||
],
|
}
|
||||||
|
],
|
||||||
"syntax_override":
|
"syntax_override":
|
||||||
{
|
{
|
||||||
"\\.js$":
|
"\\.js$":
|
||||||
|
|
|
||||||
22
package.json
22
package.json
|
|
@ -13,24 +13,28 @@
|
||||||
"author": "Danude Sandstorm",
|
"author": "Danude Sandstorm",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"react": "^15.4.1",
|
"mobx": "^3.3.1",
|
||||||
"react-dom": "^15.4.1",
|
"mobx-react": "^4.3.3",
|
||||||
"react-interactive": "^0.5.1",
|
"prop-types": "^15.6.0",
|
||||||
"react-router": "^3.0.0",
|
"react": "^16.0.0",
|
||||||
|
"react-dom": "^16.0.0",
|
||||||
|
"react-interactive": "^0.8.1",
|
||||||
|
"react-router": "^3.2.0",
|
||||||
|
"react-router-dom": "^4.2.2",
|
||||||
"whatwg-fetch": "^2.0.3"
|
"whatwg-fetch": "^2.0.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"babel-core": "^6.21.0",
|
"babel-core": "^6.21.0",
|
||||||
"babel-eslint": "^7.1.1",
|
"babel-eslint": "^8.0.0",
|
||||||
"babel-loader": "^6.2.10",
|
"babel-loader": "^6.2.10",
|
||||||
"babel-preset-es2015": "^6.18.0",
|
"babel-preset-es2015": "^6.18.0",
|
||||||
"babel-preset-react": "^6.16.0",
|
"babel-preset-react": "^6.16.0",
|
||||||
"babel-preset-stage-1": "^6.16.0",
|
"babel-preset-stage-1": "^6.16.0",
|
||||||
"eslint": "^3.12.2",
|
"eslint": "^4.0.0",
|
||||||
"eslint-config-airbnb": "^13.0.0",
|
"eslint-config-airbnb": "^16.0.0",
|
||||||
"eslint-plugin-import": "^2.2.0",
|
"eslint-plugin-import": "^2.2.0",
|
||||||
"eslint-plugin-jsx-a11y": "^2.2.3",
|
"eslint-plugin-jsx-a11y": "^6.0.0",
|
||||||
"eslint-plugin-react": "^6.8.0",
|
"eslint-plugin-react": "^7.0.0",
|
||||||
"webpack": "^1.14.0",
|
"webpack": "^1.14.0",
|
||||||
"webpack-dev-server": "^1.16.2"
|
"webpack-dev-server": "^1.16.2"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import React, { PropTypes } from 'react';
|
import React from 'react';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
import Interactive from 'react-interactive';
|
import Interactive from 'react-interactive';
|
||||||
import { Link } from 'react-router';
|
import { Link } from 'react-router';
|
||||||
import s from './styles/app.style';
|
import s from './styles/app.style';
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import React, { PropTypes } from 'react';
|
import React from 'react';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
import Interactive from 'react-interactive';
|
import Interactive from 'react-interactive';
|
||||||
import { Link } from 'react-router';
|
import { Link } from 'react-router';
|
||||||
import s from '../styles/exampleComponent.style';
|
import s from '../styles/exampleComponent.style';
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import React, { PropTypes } from 'react';
|
import React from 'react';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
import Interactive from 'react-interactive';
|
import Interactive from 'react-interactive';
|
||||||
import { Link } from 'react-router';
|
import { Link } from 'react-router';
|
||||||
import s from '../styles/exampleTwoDeepComponent.style';
|
import s from '../styles/exampleTwoDeepComponent.style';
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import React, { PropTypes } from 'react';
|
import React from 'react';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
import s from '../styles/pageNotFound.style';
|
import s from '../styles/pageNotFound.style';
|
||||||
|
|
||||||
const propTypes = {
|
const propTypes = {
|
||||||
|
|
|
||||||
|
|
@ -1,39 +1,44 @@
|
||||||
import React from 'react';
|
|
||||||
import 'whatwg-fetch';
|
import 'whatwg-fetch';
|
||||||
|
import CardsDB from './database/cards';
|
||||||
|
import PortalDB from './database/portal';
|
||||||
|
|
||||||
class URLS {
|
class API {
|
||||||
static base_url = "https://spreadsheets.google.com/feeds/list/";
|
static base_url = "https://spreadsheets.google.com/feeds/list/";
|
||||||
static data_format = "/od6/public/values?alt=json";
|
static data_format = "/od6/public/values?alt=json";
|
||||||
// + "/od6/public/basic?alt=json"; // Alternate data format
|
// + "/od6/public/basic?alt=json"; // Alternate data format
|
||||||
static base_spreadsheet = "1cUNmwV693zl2zqbH_IG4Wz8o9Va_sOHe7pAZF6M59Es";
|
static base_spreadsheet = "1cUNmwV693zl2zqbH_IG4Wz8o9Va_sOHe7pAZF6M59Es";
|
||||||
get base_image() { return "https://drive.google.com/uc?id="; }
|
get base_image() { return "https://drive.google.com/uc?id="; }
|
||||||
|
|
||||||
static path(spreadsheetID) {
|
|
||||||
return URLS.base_url + spreadsheetID + URLS.data_format;
|
|
||||||
}
|
|
||||||
|
|
||||||
constructor() {
|
|
||||||
// This sets up urls
|
|
||||||
this.urls = {};
|
|
||||||
var self = this;
|
|
||||||
this.getSpreadsheet(URLS.path(URLS.base_spreadsheet), function(data) {
|
|
||||||
data.forEach(function(d) {
|
|
||||||
if (!self.urls[d.gsx$type.$t]) self.urls[d.gsx$type.$t] = {};
|
|
||||||
self.urls[d.gsx$type.$t][d.gsx$subtype.$t] = d.gsx$url.$t;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Singleton
|
// Singleton
|
||||||
instance = null;
|
instance = null;
|
||||||
static getInstance() {
|
static getInstance() {
|
||||||
if (!URLS.instance) { URLS.instance = new URLS(); }
|
if (!API.instance) { API.instance = new API(); }
|
||||||
return URLS.instance;
|
return API.instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
static path(spreadsheetID) {
|
||||||
|
return API.base_url + spreadsheetID + API.data_format;
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
// This sets up urls and kicks off db
|
||||||
|
this.urls = {};
|
||||||
|
this.getSpreadsheet(API.path(API.base_spreadsheet), function(data) {
|
||||||
|
if (data == null) return;
|
||||||
|
data.forEach(function(d) {
|
||||||
|
if (!self.urls[d.gsx$type.$t]) self.urls[d.gsx$type.$t] = {};
|
||||||
|
self.urls[d.gsx$type.$t][d.gsx$subtype.$t] = API.path(d.gsx$url.$t);
|
||||||
|
});
|
||||||
|
self.setupDB();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
getSpreadsheet(spreadsheet, callback) {
|
getSpreadsheet(spreadsheet, callback) {
|
||||||
fetch(spreadsheet)
|
fetch(spreadsheet)
|
||||||
.then(function(response) {
|
.then(function(response) {
|
||||||
|
// console.log(response);
|
||||||
return response.json();
|
return response.json();
|
||||||
}).then(function(json) {
|
}).then(function(json) {
|
||||||
return callback(json.feed.entry);
|
return callback(json.feed.entry);
|
||||||
|
|
@ -43,31 +48,15 @@ class URLS {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Creatures */
|
setupDB() {
|
||||||
/* TODO remove legacy getters when introducing state management*/
|
try {
|
||||||
get Creatures_Card_Data() {
|
this.portal = new PortalDB(this);
|
||||||
return URLS.path("1fUFYhG1NLLkSTzrdbevm6ZMKNP6xLiKUZvM1sY10pVI");
|
this.cards = new CardsDB(this);
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
console.log('setting up database failed', err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
get Creatures() {
|
|
||||||
return {
|
|
||||||
'Overworld': URLS.path("1Z4_MmlV7uE34nLzrcxslqQKRwL4OBXNA15s7G8eteXU"),
|
|
||||||
'Underworld': URLS.path("1c_XAxQsDIWVdzUxWl5t-K_mQumNjX-yrg0X-0NsZVts"),
|
|
||||||
'Mipedian': URLS.path("1P4FKASfnhR46j2bqm89T9xhI1Yyyy-jiZ1CkRglSy2k"),
|
|
||||||
'Danian': URLS.path("1-Lz-itwOobEvqr8HSLFFwg3JFkT64NbwyGFEPfj9rxU")
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
get Mugic() {
|
|
||||||
return {
|
|
||||||
'Overworld': URLS.path("1KsVX5SkygwPP6I8yd6xgcN8gB746o_FTh6SK1TvAcbU"),
|
|
||||||
'Underworld': URLS.path("1F7FHlob52cb_7J65cddM3The7w-kFiStBRd5wm4JRlA"),
|
|
||||||
'Mipedian': URLS.path("1QDsiSUuBV_4Jn6mvl96EGU06XEoVqILGN4suYKvh9CA"),
|
|
||||||
'Danian': URLS.path("1tEuwPGixJH2A03YtYL6Ar-MSFvtfrlaveT98GwJhw1g"),
|
|
||||||
'Generic': URLS.path("1M9iAbpYAHq_ppwm0PZKUvZGfu-zbrK1CZMY16m4Plf8")
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default URLS.getInstance();
|
export default API.getInstance();
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import React, { PropTypes } from 'react';
|
import React from 'react';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
import s from '../styles/pageNotFound.style';
|
import s from '../styles/pageNotFound.style';
|
||||||
|
|
||||||
const propTypes = {
|
const propTypes = {
|
||||||
|
|
|
||||||
35
src/components/database/cards.js
Normal file
35
src/components/database/cards.js
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
export default class CardsDB {
|
||||||
|
constructor(API) {
|
||||||
|
// this.api = API;
|
||||||
|
// this.attacks = db.addCollection('attacks');
|
||||||
|
// this.battlegear = db.addCollection('battlegear');
|
||||||
|
// this.creatures = db.addCollection('creatures');
|
||||||
|
// this.locations = db.addCollection('locations');
|
||||||
|
// this.mugic = db.addCollection('mugic');
|
||||||
|
// this.db = db;
|
||||||
|
}
|
||||||
|
|
||||||
|
setupCreatures(spreadsheet) {
|
||||||
|
this.getSpreadsheet(spreadsheet, function(json) {
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
setupMugic(spreadsheet) {
|
||||||
|
this.getSpreadsheet(spreadsheet, function(json) {
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
setupBattleGear(spreadsheet) {
|
||||||
|
this.getSpreadsheet(spreadsheet, function(json) {
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
setupLocations(spreadsheet) {
|
||||||
|
this.getSpreadsheet(spreadsheet, function(json) {
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
85
src/components/database/portal.js
Normal file
85
src/components/database/portal.js
Normal file
|
|
@ -0,0 +1,85 @@
|
||||||
|
import loki from 'lokijs';
|
||||||
|
|
||||||
|
export default class PortalDB {
|
||||||
|
constructor(API) {
|
||||||
|
this.api = API;
|
||||||
|
this.setupDB();
|
||||||
|
this.setupCreatures("Overworld");
|
||||||
|
}
|
||||||
|
|
||||||
|
setupDB() {
|
||||||
|
var self = this;
|
||||||
|
// let db = new loki("chaotic_portal.db", { autosave: true, autoload: true, autoloadCallback: databaseInitialize, autosaveInterval: 4000, persistenceMethod: 'localStorage' });
|
||||||
|
let db = new loki("chaotic_portal.db"); // ignoring persistence for now
|
||||||
|
this.attacks = db.addCollection('attacks');
|
||||||
|
this.battlegear = db.addCollection('battlegear');
|
||||||
|
this.creatures = db.addCollection('creatures');
|
||||||
|
this.locations = db.addCollection('locations');
|
||||||
|
this.mugic = db.addCollection('mugic');
|
||||||
|
this.db = db;
|
||||||
|
|
||||||
|
// function databaseInitialize() {
|
||||||
|
// var entries;
|
||||||
|
// if ((entries = db.getCollection("attacks")) === null)
|
||||||
|
// entries = db.addCollection("attacks");
|
||||||
|
// self.attacks = entries;
|
||||||
|
|
||||||
|
// if ((entries = db.getCollection("battlegear")) === null)
|
||||||
|
// entries = db.addCollection("battlegear");
|
||||||
|
// self.battlegear = entries;
|
||||||
|
|
||||||
|
// console.log(db.getCollection("creatures"));
|
||||||
|
// if ((entries = db.getCollection("creatures")) === null)
|
||||||
|
// entries = db.addCollection("creatures");
|
||||||
|
// self.creatures = db.addCollection('creatures');
|
||||||
|
|
||||||
|
// if ((entries = db.getCollection("locations")) === null)
|
||||||
|
// entries = db.addCollection("locations");
|
||||||
|
// self.locations = entries
|
||||||
|
|
||||||
|
// if ((entries = db.getCollection("mugic")) === null)
|
||||||
|
// entries = db.addCollection("mugic");
|
||||||
|
// self.mugic = entries;
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
setup(spreadsheet, callback) {
|
||||||
|
this.api.getSpreadsheet(spreadsheet, function(data) {
|
||||||
|
data.map(function(item) {
|
||||||
|
// delete item.category;
|
||||||
|
// delete item.id;
|
||||||
|
// delete item.updated;
|
||||||
|
// delete item.content;
|
||||||
|
// delete item.link;
|
||||||
|
// delete item.title;
|
||||||
|
item.name = item.gsx$name.$t;
|
||||||
|
return item;
|
||||||
|
});
|
||||||
|
callback(data);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
setupAttacks() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
setupBattleGear() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
setupCreatures(tribe) {
|
||||||
|
// console.log(this);
|
||||||
|
var self = this;
|
||||||
|
this.setup(this.api.urls.Creatures[tribe], function(data) {
|
||||||
|
self.creatures.insert(data);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
setupLocations() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
setupMugic(tribe) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -19,6 +19,10 @@ export default {
|
||||||
extensions: ['', '.js', '.jsx'],
|
extensions: ['', '.js', '.jsx'],
|
||||||
},
|
},
|
||||||
|
|
||||||
|
node: {
|
||||||
|
fs: 'empty'
|
||||||
|
},
|
||||||
|
|
||||||
plugins: process.argv.indexOf('-p') === -1 ? null : [
|
plugins: process.argv.indexOf('-p') === -1 ? null : [
|
||||||
new webpack.DefinePlugin({
|
new webpack.DefinePlugin({
|
||||||
'process.env.NODE_ENV': JSON.stringify('production'),
|
'process.env.NODE_ENV': JSON.stringify('production'),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user