Skip to content

Commit

Permalink
Added observable classes
Browse files Browse the repository at this point in the history
  • Loading branch information
nippur72 committed Aug 1, 2015
1 parent 0e786fb commit b97a5da
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 11 deletions.
18 changes: 17 additions & 1 deletion Test/app.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions Test/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,26 @@ function main() {
riot.mount('*');

riot.route("welcome/nino.porcino");

var p = new Car();

p.trigger("start");
}

class Car extends Riot.Observable
{
constructor()
{
super();

this.on('start', ()=>
{
console.log("car started!");
});
}
}





12 changes: 7 additions & 5 deletions riot-ts.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ declare module Riot {
interface Settings {
brackets: string;
}
interface Observable {
on(events: string, callback: Function): any;
one(events: string, callback: Function): any;
off(events: string): any;
trigger(eventName: string, ...args: any[]): any;
class Observable {
on(events: string, callback: Function): void;
one(events: string, callback: Function): void;
off(events: string): void;
trigger(eventName: string, ...args: any[]): void;
constructor();
}
interface Router {
(callback: Function): any;
Expand All @@ -31,6 +32,7 @@ declare module Riot {
tag(tagName: string, html: string, css?: string, attrs?: string, constructor?: Function): any;
tag(tagName: string, html: string, constructor?: Function): any;
class(element: Function): void;
observable(object: any): void;
route: Riot.Router;
}
class Element implements Riot.Observable {
Expand Down
16 changes: 16 additions & 0 deletions riot-ts.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 10 additions & 5 deletions riot-ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@
brackets: string;
}

export interface Observable {
on(events: string,callback: Function);
one(events: string,callback: Function);
off(events: string);
trigger(eventName: string, ...args);
export class Observable {
on(events: string, callback: Function) {}
one(events: string, callback: Function) {}
off(events: string) {}
trigger(eventName: string, ...args) {}

constructor() {
riot.observable(this);
}
}

export interface Router {
Expand All @@ -32,6 +36,7 @@
tag(tagName: string, html: string,css?: string,attrs?: string,constructor?: Function);
tag(tagName: string, html: string, constructor?: Function);
class(element: Function): void;
observable(object: any): void;

// TODO compiler and parser

Expand Down

0 comments on commit b97a5da

Please sign in to comment.