本文整理匯總了TypeScript中@ember/object.extend函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript extend函數的具體用法?TypeScript extend怎麽用?TypeScript extend使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了extend函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: testObserver
function testObserver() {
EmberObject.extend({
// TODO: enable after https://github.com/typed-ember/ember-cli-typescript/issues/290
// valueObserver: observer('value', () => {
// // Executes whenever the "value" property changes
// })
});
}
示例2: testOnce
function testOnce() {
EmberObject.extend({
init() {
run.once(this, 'processFullName');
},
processFullName() {
}
});
}
示例3: test
test('didResize and debouncedDidResize hooks are on the object', (assert: Assert) => {
const resizeAwareObject = EObj.extend(ResizeAwareMixin);
const subject = resizeAwareObject.create();
assert.ok(subject.didResize, 'didResize hook is present on the subject');
assert.equal(typeof subject.didResize, 'function', 'didResize hook is a function');
assert.ok(subject.debouncedDidResize, 'debouncedDidResize hook is present on the subject');
assert.equal(typeof subject.debouncedDidResize, 'function', 'debouncedDidResize hook is a function');
});
示例4: testOn
function testOn() {
const Job = EmberObject.extend({
logCompleted: on('completed', () => {
console.log('Job completed!');
})
});
const job = Job.create();
sendEvent(job, 'completed'); // Logs 'Job completed!'
}
示例5: testBind
function testBind() {
EmberObject.extend({
init() {
const bound = run.bind(this, this.setupEditor);
bound();
},
editor: null as string | null,
setupEditor(editor: string) {
this.set('editor', editor);
}
});
}
示例6: testListener
function testListener() {
EmberObject.extend({
init() {
addListener(this, 'willDestroy', this, 'willDestroyListener');
addListener(this, 'willDestroy', this, 'willDestroyListener', true);
addListener(this, 'willDestroy', this, this.willDestroyListener);
addListener(this, 'willDestroy', this, this.willDestroyListener, true);
removeListener(this, 'willDestroy', this, 'willDestroyListener');
removeListener(this, 'willDestroy', this, this.willDestroyListener);
},
willDestroyListener() {
}
});
}
示例7: testSchedule
function testSchedule() {
EmberObject.extend({
init() {
run.schedule('sync', this, () => {
// this will be executed in the first RunLoop queue, when bindings are synced
console.log('scheduled on sync queue');
});
run.schedule('actions', this, () => {
// this will be executed in the 'actions' queue, after bindings have synced.
console.log('scheduled on actions queue');
});
}
});
run.schedule('actions', () => {
// Do more things
});
}
示例8: testEvented
function testEvented() {
const Person = EmberObject.extend(Evented, {
greet() {
this.trigger('greet');
}
});
const person = Person.create();
person.on('greet', () => {
console.log('Our person has greeted');
});
person.on('greet', () => {
console.log('Our person has greeted');
}).one('greet', () => {
console.log('Offer one-time special');
}).off('event', {}, () => {});
person.greet();
}
示例9: testDebounce
function testDebounce() {
function runIt() {
}
const myContext = { name: 'debounce' };
run.debounce(runIt, 150);
run.debounce(myContext, runIt, 150);
run.debounce(myContext, runIt, 150, true);
EmberObject.extend({
searchValue: 'test',
fetchResults(value: string) {},
actions: {
handleTyping() {
// the fetchResults function is passed into the component from its parent
run.debounce(this, this.get('fetchResults'), this.get('searchValue'), 250);
}
}
});
}
示例10:
import { assertType } from './lib/assert';
import EmberObject from '@ember/object';
const ExtendClass = EmberObject.extend({
foo: 'hello'
});
class ES6Class extends EmberObject {
bar: string;
}
const TestClass = EmberObject;
if (ExtendClass.detect(TestClass)) {
assertType<string>(TestClass.create().foo);
}
if (ES6Class.detect(TestClass)) {
assertType<string>(TestClass.create().bar);
}