Created
October 14, 2012 05:34
-
-
Save joeriks/3887503 to your computer and use it in GitHub Desktop.
typescript-amplify amplifyjs
This file contains hidden or 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 amplify { | |
export function subscribe(topic: string, callback: Function): void; | |
export function subscribe(topic: string, conext: Object, callback: Function): void; | |
export function subscribe(topic: string, callback: Function, priority: number): void; | |
export function subscribe(topic: string, context: Object, callback: Function, priority: number): void; | |
export function unsubscribe(topic: string, callback: Function): void; | |
export function publish(topic: string, ...args: any[]): void; | |
export function store(key: string, value: Object, args?: any): void; | |
export function store(key: string): Object; | |
export function store(): Object; | |
export module request { | |
export function (resourceId: string, data: any, callback: Function): void; | |
export function (settings: any); | |
export function define(resourceId: string, requestType: string, settings: any): void; | |
export function define(resourceId: string, resource:Function): void; | |
} | |
} |
This file contains hidden or 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
/// <reference path="../libs/jasmine.d.ts"/> | |
/// <reference path="../app/transaction.ts"/> | |
/// <reference path="../app/transaction.js"/> | |
/// <reference path="../libs/amplify.d.ts"/> | |
/// <reference path="../libs/amplify.min.js"/> | |
describe("amplify store", () => { | |
it("can store item", () => { | |
amplify.store("key1", "foo"); | |
var result = amplify.store("key1"); | |
expect(result).toBe("foo"); | |
}); | |
it("can store transactions", () => { | |
var repo = new Repository(); | |
repo.addAccount("1", "acct1"); | |
repo.addAccount("2", "acct2"); | |
repo.addAccount("3", "acct3"); | |
amplify.store("accts", repo); | |
var result = <Repository>amplify.store("accts"); | |
expect(result.accounts.length).toBe(3); | |
}); | |
it("can publish", () => { | |
var message: string; | |
var received: bool; | |
amplify.subscribe("foo", (message: string) =>{ | |
this.message = message; | |
this.received = true; | |
}); | |
amplify.publish("foo", "hello"); | |
waitsFor(function () { | |
return this.received; | |
}, "timeout", 1000); | |
runs(function () { | |
expect(this.message).toEqual("hello"); | |
}); | |
}); | |
it("syntax test basic request sample ", () => { | |
amplify.request.define("ajaxExample1", "ajax", { | |
url: "/myApiUrl", | |
dataType: "json", | |
type: "GET" | |
}); | |
// later in code | |
amplify.request("ajaxExample1", function (data) { | |
data.foo; // bar | |
}); | |
}); | |
it("syntax test Set up and use a request utilizing Ajax and Caching", () => { | |
amplify.request.define("ajaxExample2", "ajax", { | |
url: "/myApiUrl", | |
dataType: "json", | |
type: "GET", | |
cache: "persist" | |
}); | |
// later in code | |
amplify.request("ajaxExample2", function (data) { | |
data.foo; // bar | |
}); | |
// a second call will result in pulling from the cache | |
amplify.request("ajaxExample2", function (data) { | |
data.baz; // qux | |
}) | |
}); | |
it("syntax test Post data using ajax", () => { | |
amplify.request.define("ajaxPostExample", "ajax", { | |
url: "/myRestFulApi", | |
type: "POST" | |
}) | |
// later in code | |
amplify.request("ajaxPostExample", | |
{ | |
type: "foo", | |
id: "bar" | |
}, | |
function (data) { | |
data.foo; // bar | |
} | |
); | |
}); | |
}); |
Maybe update to support 0.9 of typescript;
interface AmplifyStatic {
subscribe(topic: string, callback: Function): void;
subscribe(topic: string, conext: Object, callback: Function): void;
subscribe(topic: string, callback: Function, priority: number): void;
subscribe(topic: string, context: Object, callback: Function, priority: number): void;
unsubscribe(topic: string, callback: Function): void;
publish(topic: string, ...args: any[]): void;
store(key: string, value: Object, args?: any): void;
store(key: string): Object;
store(): Object;
request: AmplifyRequestStatic;
}
interface AmplifyRequestStatic {
(resourceId: string, data: any, callback: Function): void;
(settings: any): void;
define(resourceId: string, requestType: string, settings: any): void;
define(resourceId: string, resource: Function): void;
}
declare var amplify: AmplifyStatic;
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
jasmine d.ts : https://gist.github.com/3887505