From 83319ba26fc93185d8b81ec858341a63981f9e3d Mon Sep 17 00:00:00 2001 From: Boris Yankov Date: Fri, 19 Oct 2012 20:27:25 +0300 Subject: [PATCH] Initial ember.js declarations and tests --- Definitions/ember-1.0.d.ts | 43 ++++++++++++++++++++++++ Tests/ember-tests.ts | 68 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+) create mode 100644 Definitions/ember-1.0.d.ts create mode 100644 Tests/ember-tests.ts diff --git a/Definitions/ember-1.0.d.ts b/Definitions/ember-1.0.d.ts new file mode 100644 index 000000000..4dfafcb09 --- /dev/null +++ b/Definitions/ember-1.0.d.ts @@ -0,0 +1,43 @@ +// Type definitions for Ember.js 1.0 +// Project: http://emberjs.com/ +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +module Em { + + // $; + export function A(arr?: any[]): NativeArray; + export function addListener(obj: any, eventName: string, targetOrMethod: any, method: any): void; + export function alias(methodName: Descriptor): Alias; + export function assert(desc: string, test: bool): void; + export function beforeObserver(func: Function, propertyNames: string): Function; + export function bind(obj: any, to: string, from: string): Binding; + export function cacheFor(obj: any, key: string): void; + + + export interface Alias { + } + + class Application { + static create(): Application; + MyView: View; + } + + export interface ArrayController { + } + + export interface Binding { + } + + export interface Descriptor { + } + + export interface NativeArray { + activate(): void; + } + + export interface Object { + } + + export class View { + } +} diff --git a/Tests/ember-tests.ts b/Tests/ember-tests.ts new file mode 100644 index 000000000..2289a1d44 --- /dev/null +++ b/Tests/ember-tests.ts @@ -0,0 +1,68 @@ +/// + +var App; + +App = Em.Application.create(); + +App.MyView = Em.View.extend({ + mouseDown: function() { + window.alert("hello world!"); +}); + +class MyView extends Em.View { + mouseDown() { + window.alert("hello world!"); + } +} + +App.Person = DS.Model.extend({ + firstName: DS.attr('string'), + lastName: DS.attr('string'), + fullName: function() { + return this.get('firstName') + + " " + this.get('lastName'); + }.property('firstName', 'lastName') +}); +App.peopleController = Em.ArrayController.create({ + content: App.Person.findAll() +}); + +App.president = Ember.Object.create({ + name: "Barack Obama" +}); +App.country = Ember.Object.create({ + presidentNameBinding: 'App.president.name' +}); +App.country.get('presidentName'); + +App.president = Ember.Object.create({ + firstName: "Barack", + lastName: "Obama", + fullName: function() { + return this.get('firstName') + ' ' + this.get('lastName'); + }.property() +}); +App.president.get('fullName'); + +App.president = Ember.Object.create({ + firstName: "Barack", + lastName: "Obama", + fullName: function() { + return this.get('firstName') + ' ' + this.get('lastName'); + }.property('firstName', 'lastName') +}); + +App.PaintSample = Ember.Object.extend({ + color: 'red', + colour: Ember.alias('color'), + name: function () { + return "Zed"; + }, + moniker: Ember.alias("name") +}); +var paintSample = App.PaintSample.create(); +paintSample.get('colour'); +paintSample.moniker(); + +Ember.assert('Must pass a valid object', obj); +Ember.assert('This code path should never be run');