Skip to content

Commit

Permalink
Transform kaaya to a static class
Browse files Browse the repository at this point in the history
  • Loading branch information
kefniark committed Nov 2, 2019
1 parent 13eeab3 commit 604b08a
Show file tree
Hide file tree
Showing 13 changed files with 1,528 additions and 1,722 deletions.
905 changes: 494 additions & 411 deletions build/kaaya.es.mjs

Large diffs are not rendered by default.

905 changes: 494 additions & 411 deletions build/kaaya.js

Large diffs are not rendered by default.

905 changes: 494 additions & 411 deletions build/kaaya.umd.js

Large diffs are not rendered by default.

418 changes: 14 additions & 404 deletions package-lock.json

Large diffs are not rendered by default.

23 changes: 5 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "kaaya",
"description": "DataStore synchronization library",
"version": "0.0.6",
"version": "0.0.7",
"main": "build/kaaya.js",
"module": "build/kaaya.es.mjs",
"types": "build/declarations/index.d.ts",
Expand Down Expand Up @@ -41,37 +41,24 @@
"update": "npm-check --update"
},
"devDependencies": {
"@types/jest": "^24.0.20",
"@types/node": "^12.11.7",
"@types/jest": "^24.0.21",
"@types/node": "^12.12.4",
"coopa": "^0.1.4",
"coveralls": "^3.0.7",
"jest": "^24.9.0",
"npm-check": "^5.9.0",
"npm-run-all": "^4.1.5",
"prettier": "^1.18.2",
"rimraf": "^3.0.0",
"rollup": "^1.26.0",
"rollup": "^1.26.2",
"rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-copy": "^3.1.0",
"rollup-plugin-filesize": "^6.2.1",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-progress": "^1.1.1",
"rollup-plugin-serve": "^1.0.1",
"rollup-plugin-terser": "^5.1.2",
"rollup-plugin-typescript": "^1.0.1",
"ts-jest": "^24.1.0",
"ts-loader": "^6.2.1",
"tslib": "^1.10.0",
"typescript": "^3.6.4"
},
"dependencies": {
"@types/yaml": "^1.2.0",
"coopa": "^0.1.1",
"js-ini": "^1.1.2",
"on-change": "^1.6.2",
"yaml": "^1.7.2"
},
"peerDependencies": {
"yaml": "^1.7.2",
"js-ini": "^1.1.2"
}
}
1 change: 1 addition & 0 deletions rollup.dev.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default {
commonjs(),
serve({
open: true,
openPage: "/samples/",
contentBase: ["."],
port: 8080,
verbose: true
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Kaaya } from "./kaaya"

export default new Kaaya()
export default Kaaya

export * from "./stores"
50 changes: 12 additions & 38 deletions src/kaaya.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// import { parse as parseIni } from "js-ini"
// import { parse as parseYaml } from "yaml"
import { Entity, TransformComponent } from "./customStore/entityComponent"
import { BaseStore, KeyStore, TableStore, EntityStore } from "./stores"
import { EntityFolder } from "./customStore/fileFolder/entityFolder"
Expand All @@ -12,7 +10,7 @@ export class Kaaya {
* @param {*} [data={}]
* @returns {BaseStore}
*/
public createRawStore(data?: any): BaseStore {
public static createRawStore(data?: any): BaseStore {
return new BaseStore(data)
}

Expand All @@ -23,69 +21,45 @@ export class Kaaya {
* @param {*} [data={}]
* @returns {KeyStore}
*/
public createKeyStore(data: any = {}): KeyStore {
public static createKeyStore(data: any = {}): KeyStore {
return new KeyStore(data)
}

/**
* Create a Keystore from a configuration file (.ini)
*
* @param {string} data
* @memberof Kaaya
*/
// public createKeyStoreFromINI(data: string): KeyStore {
// return this.createKeyStore(parseIni(data))
// }

/**
* Create a Keystore from a configuration file (.ini)
*
* @param {string} data
* @memberof Kaaya
*/
// public createKeyStoreFromYAML(data: string): KeyStore {
// return this.createKeyStore(parseYaml(data))
// }

/**
* Create a Keystore from a configuration file (.json)
*
* @param {string} data
* @memberof Kaaya
*/
public createKeyStoreFromJSON(data: string): KeyStore {
return this.createKeyStore(JSON.parse(data))
public static createKeyStoreFromJSON(data: string): KeyStore {
return Kaaya.createKeyStore(JSON.parse(data))
}
//#endregion KeyStore

//#region Table Store
public createTableStore(data?: any): TableStore {
public static createTableStore(data?: any): TableStore {
return new TableStore(data)
}

// public createTableStoreFromYAML(data: string): TableStore {
// return this.createTableStore(parseYaml(data))
// }

public createTableStoreFromJSON(data: string): TableStore {
return this.createTableStore(JSON.parse(data))
public static createTableStoreFromJSON(data: string): TableStore {
return Kaaya.createTableStore(JSON.parse(data))
}
//#endregion Table Store

public createEntityStore(data?: any): EntityStore {
public static createEntityStore(data?: any): EntityStore {
return new EntityStore(data)
}

public createEntityComponentStore(data?: any): EntityStore {
const store = this.createEntityStore(data)
public static createEntityComponentStore(data?: any): EntityStore {
const store = Kaaya.createEntityStore(data)
store.register("Entity", (store1, data1) => new Entity(store1, data1))
store.register("Transform", (store2, data2) => new TransformComponent(store2, data2))
return store
}

public createFileFolderStore(data: any = {}): EntityStore {
public static createFileFolderStore(data: any = {}): EntityStore {
if (!data.meta) data.meta = { selected: "" }
const store = this.createEntityStore(data)
const store = Kaaya.createEntityStore(data)
store.register("File", (store1, data1) => new EntityFile(store1, data1))
store.register("Folder", (store2, data2) => new EntityFolder(store2, data2))
return store
Expand Down
2 changes: 1 addition & 1 deletion src/stores/baseStore.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DataStore } from "./dataStore"
import onChange from "on-change"
import { onChange } from "coopa"
import { clone } from "../helpers/check"

export class BaseStore {
Expand Down
12 changes: 1 addition & 11 deletions src/stores/keyStore.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { BaseStore } from "./baseStore"
// import { stringify as stringifyIni } from "js-ini"
// import { stringify as stringifyYaml } from "yaml"

export class KeyStore extends BaseStore {
createSection(name: string): void {
Expand Down Expand Up @@ -38,15 +36,7 @@ export class KeyStore extends BaseStore {
delete this.data[name]
}

stringifyJSON(): string {
stringify(): string {
return JSON.stringify(this.data, null, 2)
}

// stringifyINI(): string {
// return stringifyIni(this.data)
// }

// stringifyYAML(): string {
// return stringifyYaml(this.data)
// }
}
7 changes: 1 addition & 6 deletions src/stores/tableStore.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { BaseStore } from "./baseStore"
// import { stringify as stringifyYaml } from "yaml"
import { uid } from "coopa"
import { clone } from "../helpers/check"

Expand Down Expand Up @@ -104,11 +103,7 @@ export class TableStore extends BaseStore {
delete this.data[name]
}

stringifyJSON(): string {
stringify(): string {
return JSON.stringify(this.getValues(), null, 2)
}

// stringifyYAML(): string {
// return stringifyYaml(this.getValues())
// }
}
10 changes: 5 additions & 5 deletions tests/keystore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ test("JSON File", () => {
expect(iniStore.data.SectionTwo.integer).toBe(1234)

// export file to a new ini file
const result = iniStore.stringifyJSON()
const result = iniStore.stringify()
expect(result).toContain("東京") // check value where properly changed
expect(result).toContain('"SectionThree":') // check new section are there too
})
Expand All @@ -114,7 +114,7 @@ test("JSON File", () => {
// integer: 1234
// `
// // import from ini file
// const iniStore = Kaaya.createKeyStoreFromYAML(yamlData)
// const iniStore = KaayaYaml.createKeyStore(yamlData)

// // check the contents
// expect(iniStore.data.SectionOne.key).toBe("value")
Expand All @@ -124,7 +124,7 @@ test("JSON File", () => {
// expect(iniStore.data.SectionTwo.integer).toBe(1234)

// // export file to a new ini file
// const result = iniStore.stringifyYAML()
// const result = KaayaYaml.stringify(iniStore)
// expect(result).toContain("東京") // check value where properly changed
// expect(result).toContain("SectionThree:") // check new section are there too
// })
Expand All @@ -149,7 +149,7 @@ test("JSON File", () => {
// integer = 1234
// `
// // import from ini file
// const iniStore = Kaaya.createKeyStoreFromINI(iniData)
// const iniStore = KaayaIni.createKeyStore(iniData)

// // check the contents
// expect(iniStore.data.SectionOne.key).toBe("value")
Expand All @@ -159,7 +159,7 @@ test("JSON File", () => {
// expect(iniStore.data.SectionTwo.integer).toBe(1234)

// // export file to a new ini file
// const result = iniStore.stringifyINI()
// const result = KaayaIni.stringify(iniStore)
// expect(result).toContain("東京") // check value where properly changed
// expect(result).toContain("[SectionThree]") // check new section are there too
// })
10 changes: 5 additions & 5 deletions tests/tablestore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ test("JSON File", () => {
store.addRow("youhou", { name: "salmon", age: 2, mail: "salmon@fish.com" })

expect(store.getCell("youhou", "tuna", "age")).toBe(1)
expect(store.stringifyJSON()).toContain('"youhou":')
expect(store.stringify()).toContain('"youhou":')
})

// test("Yaml File", () => {
Expand All @@ -107,15 +107,15 @@ test("JSON File", () => {
// def: 8
// `
// // import from ini file
// const store = Kaaya.createTableStoreFromYAML(yamlData)
// const store2 = Kaaya.createTableStoreFromYAML(yamlData)
// const store = KaayaYaml.createTableStore(yamlData)
// const store2 = KaayaYaml.createTableStore(yamlData)
// store.observe(_mut => store2.sync(store.history))

// store.createSheet("youhou")
// store.addRow("youhou", { id: "tuna", name: "tuna", age: 1, mail: "tuna@fish.com" })
// store.addRow("youhou", { name: "salmon", age: 2, mail: "salmon@fish.com" })

// expect(store.getCell("youhou", "tuna", "age")).toBe(1)
// expect(store2.stringifyYAML()).toContain("youhou:")
// expect(store2.stringifyJSON()).toContain('"youhou":')
// expect(KaayaYaml.stringify(store2)).toContain("youhou:")
// expect(store2.stringify()).toContain('"youhou":')
// })

0 comments on commit 604b08a

Please sign in to comment.