Last active
October 29, 2015 01:47
-
-
Save blakef/b098bd06df561ee53a13 to your computer and use it in GitHub Desktop.
TypeScript + RxJS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import path = require('path'); | |
import Git = require('nodegit'); | |
import Rx = require('rx'); | |
class Repo { | |
private repo: Rx.Observable<Git.Repository>; | |
constructor(private pathname: string) { | |
this.repo = Rx.Observable.fromPromise(Git.Repository.open(pathname)); | |
} | |
branches() { | |
this.repo | |
.flatMap(repository => repository.getCurrentBranch()) | |
.subscribe(reference => console.log(reference.name())) | |
; | |
} | |
} | |
var dir: string = path.resolve('../path/to/git/repo'); | |
var repo: Repo = new Repo(dir); | |
repo.branches(); | |
// $ node hello.js | |
// > refs/heads/master |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare module "nodegit" { | |
export class Reference { | |
name(): string; | |
} | |
export class Repository { | |
static open(path: string): Rx.IPromise<Repository>; | |
getCurrentBranch(): Rx.IPromise<Reference>; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare module Rx { | |
declare module internals { | |
... | |
export interface IPromise<T> { | |
then<R>(onFulfilled: (value: T) => IPromise<R>, onRejected: (reason: any) => IPromise<R>): IPromise<R>; | |
then<R>(onFulfilled: (value: T) => IPromise<R>, onRejected?: (reason: any) => R): IPromise<R>; | |
then<R>(onFulfilled: (value: T) => R, onRejected: (reason: any) => IPromise<R>): IPromise<R>; | |
then<R>(onFulfilled?: (value: T) => R, onRejected?: (reason: any) => R): IPromise<R>; | |
} | |
... | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"compilerOptions": { | |
"target": "es5", | |
"module": "commonjs", | |
"moduleResolution": "node", | |
"isolatedModules": false, | |
"jsx": "react", | |
"experimentalDecorators": true, | |
"emitDecoratorMetadata": true, | |
"declaration": false, | |
"noImplicitAny": false, | |
"removeComments": true, | |
"noLib": false, | |
"preserveConstEnums": true, | |
"suppressImplicitAnyIndexErrors": true | |
}, | |
"filesGlob": [ | |
"**/*.ts", | |
"**/*.tsx", | |
"!node_modules/**" | |
], | |
"files": [ | |
"hello.ts", | |
"typings/node-git/node-git.d.ts", | |
"typings/node/node.d.ts", | |
"typings/rx/rx-lite.d.ts", | |
"typings/rx/rx.d.ts" | |
], | |
"exclude": [] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example of using TypeScript with an external library, and providing custom type definition files. This runs on Node.