本文整理汇总了TypeScript中@ember/-internals/meta.peekMeta函数的典型用法代码示例。如果您正苦于以下问题:TypeScript peekMeta函数的具体用法?TypeScript peekMeta怎么用?TypeScript peekMeta使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了peekMeta函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: key
/**
This function is called just after an object property has changed.
It will notify any observers and clear caches among other things.
Normally you will not need to call this method directly but if for some
reason you can't directly watch a property you can invoke this method
manually.
@method notifyPropertyChange
@for @ember/object
@param {Object} obj The object with the property that will change
@param {String} keyName The property key (or path) that will change.
@param {Meta} meta The objects meta.
@return {void}
@since 3.1.0
@public
*/
function notifyPropertyChange(obj: object, keyName: string, _meta?: Meta | null): void {
let meta = _meta === undefined ? peekMeta(obj) : _meta;
if (meta !== null && (meta.isInitializing() || meta.isPrototypeMeta(obj))) {
return;
}
let possibleDesc = descriptorFor(obj, keyName, meta);
if (possibleDesc !== undefined && typeof possibleDesc.didChange === 'function') {
possibleDesc.didChange(obj, keyName);
}
if (meta !== null && meta.peekWatching(keyName) > 0) {
dependentKeysDidChange(obj, keyName, meta);
chainsDidChange(obj, keyName, meta);
notifyObservers(obj, keyName, meta);
}
if (PROPERTY_DID_CHANGE in obj) {
obj[PROPERTY_DID_CHANGE](keyName);
}
if (meta !== null) {
if (meta.isSourceDestroying()) {
return;
}
markObjectAsDirty(obj, keyName, meta);
}
if (DEBUG) {
assertNotRendered(obj, keyName);
}
}
示例2: peekMeta
ACTIVE_OBSERVERS.forEach((activeObservers, target) => {
let meta = peekMeta(target);
if (meta && (meta.isSourceDestroying() || meta.isMetaDestroyed())) {
ACTIVE_OBSERVERS.delete(target);
return;
}
activeObservers.forEach((observer, eventName) => {
if (!observer.tag.validate(observer.lastRevision)) {
let sendObserver = () => {
try {
sendEvent(target, eventName, [target, observer.path]);
} finally {
observer.tag = getChainTagsForKey(target, observer.path);
observer.lastRevision = observer.tag.value();
}
};
if (shouldSchedule) {
schedule('actions', sendObserver);
} else {
// TODO: we need to schedule eagerly in exactly one location (_internalReset),
// for query params. We should get rid of this ASAP
sendObserver();
}
}
});
});
示例3: hasListeners
export function hasListeners(obj: object, eventName: string): boolean {
let meta = peekMeta(obj);
if (meta === null) {
return false;
}
let matched = meta.matchingListeners(eventName);
return matched !== undefined && matched.length > 0;
}
示例4: peekMeta
export function arrayContentDidChange<T extends { length: number }>(
array: T,
startIdx: number,
removeAmt: number,
addAmt: number
): T {
// if no args are passed assume everything changes
if (startIdx === undefined) {
startIdx = 0;
removeAmt = addAmt = -1;
} else {
if (removeAmt === undefined) {
removeAmt = -1;
}
if (addAmt === undefined) {
addAmt = -1;
}
}
let meta = peekMeta(array);
if (addAmt < 0 || removeAmt < 0 || addAmt - removeAmt !== 0) {
notifyPropertyChange(array, 'length', meta);
}
notifyPropertyChange(array, '[]', meta);
if (!EMBER_METAL_TRACKED_PROPERTIES) {
eachProxyArrayDidChange(array, startIdx, removeAmt, addAmt);
}
sendEvent(array, '@array:change', [array, startIdx, removeAmt, addAmt]);
let cache = peekCacheFor(array);
if (cache !== undefined) {
let length = array.length;
let addedAmount = addAmt === -1 ? 0 : addAmt;
let removedAmount = removeAmt === -1 ? 0 : removeAmt;
let delta = addedAmount - removedAmount;
let previousLength = length - delta;
let normalStartIdx = startIdx < 0 ? previousLength + startIdx : startIdx;
if (cache.has('firstObject') && normalStartIdx === 0) {
notifyPropertyChange(array, 'firstObject', meta);
}
if (cache.has('lastObject')) {
let previousLastIndex = previousLength - 1;
let lastAffectedIndex = normalStartIdx + removedAmount;
if (previousLastIndex < lastAffectedIndex) {
notifyPropertyChange(array, 'lastObject', meta);
}
}
}
return array;
}
示例5: SETTER_FUNCTION
function SETTER_FUNCTION(this: object, value: any | undefined | null): void {
let m = peekMeta(this)!;
if (m.isInitializing() || m.isPrototypeMeta(this)) {
m.writeValues(name, value);
} else {
assert(
`You must use set() to set the \`${name}\` property (of ${this}) to \`${value}\`.`,
false
);
}
}
示例6: detect
/**
@method detect
@param obj
@return {Boolean}
@private
*/
detect(obj: any): boolean {
if (typeof obj !== 'object' || obj === null) {
return false;
}
if (obj instanceof Mixin) {
return _detect(obj, this);
}
let meta = peekMeta(obj);
if (meta === undefined) {
return false;
}
return meta.hasMixin(this);
}
示例7: IGETTER_FUNCTION
function IGETTER_FUNCTION(this: any): void {
let meta = peekMeta(this);
let val;
if (meta !== null) {
val = meta.readInheritedValue('values', name);
if (val === UNDEFINED) {
let proto = Object.getPrototypeOf(this);
return proto === null ? undefined : proto[name];
}
}
return val;
}
示例8: arrayDidChange
arrayDidChange(content: T[] | EmberArray<T>, idx: number, _removedCnt: number, addedCnt: number) {
let keys = this._keys;
if (!keys) {
return;
}
let lim = addedCnt > 0 ? idx + addedCnt : -1;
let meta = peekMeta(this);
for (let key in keys) {
if (lim > 0) {
addObserverForContentKey(content, key, this, idx, lim);
}
notifyPropertyChange(this, key, meta);
}
}
示例9: unwatchPath
export function unwatchPath(obj: any, keyPath: string, meta?: Meta): void {
let m = meta === undefined ? peekMeta(obj) : meta;
if (m === null) {
return;
}
let counter = m.peekWatching(keyPath);
if (counter > 0) {
m.writeWatching(keyPath, counter - 1);
if (counter === 1) {
m.writableChains(makeChainNode).remove(keyPath);
}
}
}
示例10: descriptorForProperty
export function descriptorForProperty(obj: object, keyName: string, _meta?: Meta | null) {
assert('Cannot call `descriptorFor` on null', obj !== null);
assert('Cannot call `descriptorFor` on undefined', obj !== undefined);
assert(
`Cannot call \`descriptorFor\` on ${typeof obj}`,
typeof obj === 'object' || typeof obj === 'function'
);
let meta = _meta === undefined ? peekMeta(obj) : _meta;
if (meta !== null) {
return meta.peekDescriptors(keyName);
}
}