Giter Club home page Giter Club logo

kobalt's Introduction

Kobalt

Minimalistic & Precise Low Code Frontend Framework to build Scalable Web Apps

import Kobalt from "./kobalt.js"

let App = new Kobalt({
	title: "Tic Tac Toe",
	class: "boardgame",
	store: {
		gameid: {
			type: Number,
			default() => Math.random()
		},
		player: {
			type: Number,
			default: 1
		},
		cells: {
			type: Array,
			methods: {
				load() {
					this.$http.get("/gameid/" + this.$state.game + "/cells").then(response => {
						this.$stateCommit("cells", response.data) // {A1: 0, A2: 1, A3: 0, ... }
					})
				},
				setmove(cell) {
					this.$http.post("/gameid/" + this.$state.game + "/cells/" cell, {player: this.$state.player}).then(response => {
						this.$stateCommit("cells", response.data) // {A1: 0, A2: 1, A3: 0, ... }
						if(this.isWinner()){
							this.$setState("winner", this.$props.player)
						}else{
							this.$setState("player", (this.$props.player) % 2 + 1)
						}
						
					})
				}
			},
			events: {
				newmove() {
					this.load()
				}
			}
		}
	},
	state: {
		winner: 0
	},
	elements: {
		Board
	},
	methods: {
		isWinner() {
			// Todo: calculate winner. If winner: return true
			return false
		}
	},
	content: [
		{
			element: "p",
			content() => "Player: " + this.$state.player
		},{
			element: "p",
			content() => "Winner: " + this.$state.winner + ". Click to restart.",
			show() => this.$state.winner > 0,
			click() {
				this.$stateReset("winner")
				this.$storeReset("gameid")
				this.$store.cells.load()
			}
		},{
			element: "div",
			class: "board",
			content: {
				element: "Board",
				props: {
					winner() => this.$state.winner
				}
			}
		}
	]
})

let Board = {
	title: "Board",
	props: {
		winner: Number
	},
	content: {
		element: "div",
		class: "row",
		repeat: ["A", "B", "C"],
		content: {
			element: "div",
			class: "col cell",
			content: "",
			repeat: ["1", "2", "3"],
			class() => "player-" + this.$state.cells[this.$parent.$repeat.key + this.$repeat.key],
			click() {
				this.$store.setmove(this.$parent.$repeat.key + this.$repeat.key)			
			}
		}
	}
}

Documentation

API

License

MIT

Copyright 2018-present

kobalt's People

Contributors

kvdmolen avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.