forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathember-tests.ts
195 lines (168 loc) · 4.89 KB
/
ember-tests.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/// <reference path="ember.d.ts" />
/// <reference path="../handlebars/handlebars.d.ts" />
var App;
App = Em.Application.create();
App.president = Em.Object.create({
name: 'Barack Obama'
});
App.country = Em.Object.create({
presidentNameBinding: 'MyApp.president.name'
});
App.country.get('presidentName');
App.president = Em.Object.create({
firstName: 'Barack',
lastName: 'Obama',
fullName: function () {
return this.get('firstName') + ' ' + this.get('lastName');
}.property()
});
App.president.get('fullName');
declare class MyPerson extends Em.Object {
static createMan(): MyPerson;
}
var Person1 = Em.Object.extend<typeof MyPerson>({
say: (thing) => {
alert(thing);
}
});
declare class MyPerson2 extends Em.Object {
helloWorld(): void;
}
var tom = Person1.create<MyPerson2>({
name: 'Tom Dale',
helloWorld: function() {
this.say('Hi my name is ' + this.get('name'));
}
});
tom.helloWorld();
Person1.reopen({ isPerson: true });
Person1.create<Em.Object>().get('isPerson');
Person1.reopenClass({
createMan: () => {
return Person1.create({ isMan: true });
}
});
// ReSharper disable once DuplicatingLocalDeclaration
declare var Person1: typeof MyPerson;
Person1.createMan().get('isMan');
var person = Person1.create<Em.Object>({
firstName: 'Yehuda',
lastName: 'Katz'
});
person.addObserver('fullName', null, () => { });
person.set('firstName', 'Brohuda');
App.todosController = Em.Object.create({
todos: [
Em.Object.create({ isDone: false })
],
remaining: (function() {
var todos = this.get('todos');
return todos.filterProperty('isDone', false).get('length');
}).property('[email protected]')
});
var todos = App.todosController.get('todos');
var todo = todos.objectAt(0);
todo.set('isDone', true);
App.todosController.get('remaining');
todo = Em.Object.create({ isDone: false });
todos.pushObject(todo);
App.todosController.get('remaining');
App.wife = Em.Object.create({
householdIncome: 80000
});
App.husband = Em.Object.create({
householdIncomeBinding: 'App.wife.householdIncome'
});
App.husband.get('householdIncome');
App.husband.set('householdIncome', 90000);
App.wife.get('householdIncome');
App.user = Em.Object.create({
fullName: 'Kara Gates'
});
App.userView = Em.View.create({
userNameBinding: Em.Binding.oneWay('App.user.fullName')
});
App.user.set('fullName', 'Krang Gates');
App.userView.set('userName', 'Truckasaurus Gates');
App.user.get('fullName');
App = Em.Application.create({
rootElement: '#sidebar'
});
var view = Em.View.create<Em.View>({
templateName: 'say-hello',
name: 'Bob'
});
view.appendTo('#container');
view.append();
view.remove();
App.AlertView = Em.View.extend({
priority: 'p4',
isUrgent: true
});
App.ListingView = Em.View.extend({
templateName: 'listing',
edit: (event) => {
event.view.set('isEditing', true);
}
});
App.userController = Em.Object.create({
content: Em.Object.create({
firstName: 'Albert',
lastName: 'Hofmann',
posts: 25,
hobbies: 'Riding bicycles'
})
});
Handlebars.registerHelper('highlight', function(property, options) {
var value = Em.Handlebars.get(this, property, options);
return new Handlebars.SafeString('<span class="highlight">' + value + '</span>');
});
App.MyText = Em.TextField.extend({
formBlurredBinding: 'App.adminController.formBlurred',
change: function() {
this.set('formBlurred', true);
}
});
var textArea = Em.TextArea.create({
valueBinding: 'TestObject.value'
});
App.ClickableView = Em.View.extend({
click: () => {
alert('ClickableView was clicked!');
}
});
var container = Em.ContainerView.create<Em.ContainerView>();
container.append();
var coolView = App.CoolView.create(),
childViews = container.get('childViews');
childViews.pushObject(coolView);
var Person2 = Em.Object.extend<typeof Em.Object>({
sayHello: function() {
console.log('Hello from ' + this.get('name'));
}
});
var people = [
Person2.create({ name: 'Juan' }),
Person2.create({ name: 'Charles' }),
Person2.create({ name: 'Majd' })
];
people.invoke('sayHello');
var arr = [Em.Object.create(), Em.Object.create()];
arr.setEach('name', 'unknown');
arr.getEach('name');
var Person3 = Em.Object.extend<typeof Em.Object>({
name: null,
isHappy: false
});
var people2 = [
Person3.create({ name: 'Yehuda', isHappy: true }),
Person3.create({ name: 'Majd', isHappy: false })
];
people2.every((person: Em.Object) => {
return !!person.get('isHappy');
});
people2.some((person: Em.Object) => {
return !!person.get('isHappy');
});
people2.everyProperty('isHappy', true);
people2.someProperty('isHappy', true);