Giter Site home page Giter Site logo

geekyants / geekymodel Goto Github PK

View Code? Open in Web Editor NEW
6.0 3.0 3.0 1.97 MB

GeekyModel - Opinionated State Container for Remote and Local Storage with a Database-like API powered by MobX

HTML 5.00% CSS 2.74% JavaScript 30.15% TypeScript 62.12%
state-management mobx orm-framework front-end react

geekymodel's Introduction

🗄 GeekyModel

⚠️️️️️ ⚠️️️️️ ⚠️️️️️ Not for production use ⚠️️️️️ ⚠️️️️️ ⚠️️️️️

What is 🗄 GeekyModel?

GeekyModel is an opinionated State Container with a Database-like API powered by MobX.

The Data Models can later be mapped to a Remote service like Firebase, REST API, GraphQL etc.

Features ⚡

  • Build your front-end models without worrying about the back-end. GeekyModel works with LocalStorage by default.

  • Offline First: Connect to any back-end at a later stage, like

    • Firebase / Firestore
    • GraphQL
    • REST APIs
  • Write request and response middlewares to map the differences in the front-end and the back-end models.

  • Built-in standard validation and option to add custom validators.

  • Model Relationships: Relate models with References and Foreign Keys.

  • Built-in Fake Data: Populate your UI with Fake Data automatically.

Getting started

yarn add geekymodel

OR

npm install geekymodel --save

Writing your first model

import { createModel } from "geekymodel";

const Todo = createModel({
  table: "todos",
  fields: ["caption", "isCompleted"]
});

Creating a new Todo

const newTodo = Todo.create();

newTodo.setField("caption", "Buy milk");
newTodo.setField("isCompleted", "false");

newTodo.save();

// newTodo.saving gets populated which is a MobX ObservableValue

Fetching all the todos and wiring with React

@observable
class TodoApp extends Component {

    componentWillMount() {
        this.todos = Todo.findAll();
    }

    render() {

        const { data, loading } = this.todos;

        if (loading)
            return <span>Loading</span>;

        return <ul>
            {data.map(item) => <li>{item.getField('caption')}</li>}
        </ul>
    }

}

Adding query params

const allCompleted = Todo.where("isCaption", "=", true).get();

Roadmap

  • Model creation with Schema

  • Convert to monorepo

  • Injectable Transport Layer

  • Connection

    • FakeConnection
      • Improve FakeConnection to request and response on Schema
      • WIP: Implement get(), find(), insert(), update() and delete() with FakeConnection()
    • LocalStorageConnection
    • RuntimeStorageConnection
    • RuntimeMiddlewareConnection
    • FirestoreConnection
    • GraphQLConnection
    • RestConnection
  • Normalization

  • Validation

  • Middlewares:

    • Builder: For each method get(), find(), insert(), update() and delete()
    • Connection: Request and Response
  • Namespace Global variables in Database

  • Build script

  • Middlewares

  • Relationships

  • Examples:

    • Todo app
    • Hacker news clone
    • Shopping cart

Decisions

  • DatabaseSchema to be forwarded from top level to the connection

Open Questions

  • How would it work with offline first database which syncs later?

geekymodel's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  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.