0.0.17 • Published 2 years ago

@simpleseries/mvc v0.0.17

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

SimpleSeries MVC

npm install @simpleseries/mvc

Example Usage

Import SimpleSeries/MVC and extend the models you'd like to have use it. Create a directory for data files and for your todolist app:

mkdir db todolist

And add some files:

touch tsconfig.json package.json app.ts todolist/list.ts todolist/listitem.ts

We have two dependencies, @simpleseries/mvc and @types/node:

// package.json
{
    "dependencies": {
        "@simpleseries/mvc": "latest",
        "@types/node": "latest"
    }
}

define a directory for our typscript compiled javascript

// tsconfig.json
{
    "compilerOptions": {
        "outDir": "./javascript"
    }
}
// todolist/list.ts
import { MVC } from '@simpleseries/mvc';
import { ListItem } from './listitem';

class TodoList extends MVC.Model {
    name: string
    items: Array<ListItem>
    constructor(name) {
        super();
        this.name = name;
        this.items = new Array<ListItem>();       
    }

    addItem(description: string) {
        let listItem = new ListItem(this.id, description)
        this.items.push(listItem);
        listItem.create();
    }

    toString() {
        return `id: ${this.id}, name: ${this.name}`;
    }
}

export { TodoList };
// todolist/listitem.ts
import { MVC } from '@simpleseries/mvc';

class ListItem extends MVC.Model {
    listId: string;
    description: string;
    done: boolean;
    constructor(listId: string, description: string){
        super();
        this.listId = listId;
        this.description = description;
        this.done = false;
    }

    toString() {
        return `id: ${this.id}, listId: ${this.listId}, description: ${this.description}, done: ${this.done}`
    }
}

export { ListItem }
// app.js
import { TodoList } from './todolist/list';


let todoList = new TodoList("My List");
todoList.addItem("buy milk");
todoList.addItem("buy cheese");
todoList.addItem("take a shower");
todoList.addItem("brush teeth");

todoList.create();

compile and run

ts
node javascript/app.js
0.0.17

2 years ago

0.0.16

2 years ago

0.0.15

2 years ago

0.0.14

2 years ago

0.0.13

2 years ago

0.0.12

2 years ago

0.0.11

2 years ago

0.0.10

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago