本文整理匯總了TypeScript中underscore.isFunction函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript isFunction函數的具體用法?TypeScript isFunction怎麽用?TypeScript isFunction使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了isFunction函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: addSubscriber
/**
* add a subscriber to the WatchDog.
* @method addSubscriber
*
* add a subscriber to the WatchDog.
*
* This method modifies the subscriber be adding a
* new method to it called 'keepAlive'
* The subscriber must also provide a "watchdogReset". watchdogReset will be called
* if the subscriber failed to call keepAlive withing the timeout period.
* @param subscriber
* @param timeout
* @return the numerical key associated with this subscriber
*/
public addSubscriber(subscriber: ISubscriber, timeout: number): number {
const self = this;
self._currentTime = Date.now();
timeout = timeout || 1000;
assert(_.isNumber(timeout), " invalid timeout ");
assert(_.isFunction(subscriber.watchdogReset), " the subscriber must provide a watchdogReset method ");
assert(!_.isFunction(subscriber.keepAlive));
self._counter += 1;
const key = self._counter;
subscriber._watchDog = self;
subscriber._watchDogData = {
key,
lastSeen: self._currentTime,
subscriber,
timeout,
visitCount: 0
} as IWatchdogData2;
self._watchdogDataMap[key] = subscriber._watchDogData;
if (subscriber.onClientSeen) {
subscriber.onClientSeen(new Date(subscriber._watchDogData.lastSeen));
}
subscriber.keepAlive = keepAliveFunc.bind(subscriber);
// start timer when the first subscriber comes in
if (self.subscriberCount === 1) {
assert(self._timer === null);
this._start_timer();
}
return key;
}
示例2: constructor
constructor(options: EnumerationDefinitionOptions) {
super(options);
// create a new Enum
const typedEnum = new Enum(options.enumValues);
options.typedEnum = typedEnum;
assert(!options.encode || _.isFunction(options.encode));
assert(!options.decode || _.isFunction(options.decode));
this.encode = options.encode || _encode_enumeration;
this.decode = options.decode || function _decode_enumeration(stream: BinaryStream): EnumItem {
const value = stream.readInteger();
const e = typedEnum.get(value);
// istanbul ignore next
if (!e) {
throw new Error("cannot coerce value=" + value + " to " + typedEnum.constructor.name);
}
return e;
};
this.typedEnum = options.typedEnum;
this.defaultValue = this.typedEnum.getDefaultValue().value;
}
示例3: withSubscription
public withSubscription(
endpointUrl: string,
subscriptionParameters: ClientSubscriptionOptions,
innerFunc: (session: ClientSession, subscription: ClientSubscription, done: (err?: Error) => void) => void,
callback: (err?: Error) => void
) {
assert(_.isFunction(innerFunc));
assert(_.isFunction(callback));
this.withSession(endpointUrl, (session: ClientSession, done: (err?: Error) => void) => {
assert(_.isFunction(done));
const subscription = new ClientSubscriptionImpl(session as ClientSessionImpl, subscriptionParameters);
try {
innerFunc(session, subscription, (err?: Error) => {
subscription.terminate((err1?: Error) => {
done(err1);
});
});
} catch (err) {
debugLog(err);
done(err);
}
}, callback);
}
示例4: registerType
export function registerType(schema: BasicTypeDefinitionOptions): void {
assert(typeof schema.name === "string");
if (!_.isFunction(schema.encode)) {
throw new Error("schema " + schema.name + " has no encode function");
}
if (!_.isFunction(schema.decode)) {
throw new Error("schema " + schema.name + " has no decode function");
}
schema.category = FieldCategory.basic;
const definition = new BasicTypeSchema(schema);
_defaultTypeMap.set(schema.name, definition);
}
示例5:
Marionette.TemplateCache.prototype.compileTemplate = (rawTemplate: any): any => {
if (_.isFunction(rawTemplate)) {
return rawTemplate;
} else {
return Handlebars.compile(rawTemplate);
}
};
示例6: _self_coerce
function _self_coerce(constructor: any) {
assert(_.isFunction(constructor));
return (value: any) => {
const obj = new constructor(value);
return obj;
};
}
示例7: getEndpoints
public getEndpoints(...args: any[]): any {
if (args.length === 1) {
return this.getEndpoints({}, args[0]);
}
const options = args[0] as GetEndpointsOptions;
const callback = args[1] as ResponseCallback<EndpointDescription[]>;
assert(_.isFunction(callback));
options.localeIds = options.localeIds || [];
options.profileUris = options.profileUris || [];
const request = new GetEndpointsRequest({
endpointUrl: options.endpointUrl || this.endpointUrl,
localeIds: options.localeIds,
profileUris: options.profileUris,
requestHeader: {
auditEntryId: null
}
});
this.performMessageTransaction(request, (err: Error | null, response?: Response) => {
this._serverEndpoints = [];
if (err) {
return callback(err);
}
if (!response || !(response instanceof GetEndpointsResponse)) {
return callback(new Error("Internal Error"));
}
if (response && response.endpoints) {
this._serverEndpoints = response.endpoints;
}
callback(null, this._serverEndpoints);
});
}
示例8: debugLog
this._recreate_secure_channel((err1?: Error) => {
debugLog("secureChannel#on(close) => _recreate_secure_channel returns ",
err1 ? err1.message : "OK");
if (err1) {
// xx assert(!this._secureChannel);
debugLog("_recreate_secure_channel has failed");
// xx this.emit("close", err1);
return;
} else {
/**
* @event connection_reestablished
* send when the connection is reestablished after a connection break
*/
this.emit("connection_reestablished");
// now delegate to upper class the
if (this._on_connection_reestablished) {
assert(_.isFunction(this._on_connection_reestablished));
this._on_connection_reestablished((err2?: Error) => {
if (err2) {
debugLog("connection_reestablished has failed");
this.disconnect(() => {
// callback(err);
});
}
});
}
}
});
示例9: write_field
// --------------------------------------------------------------
// implement decode
function write_field(field: FieldType, member: string, i: number) {
if (field.category === FieldCategory.enumeration || field.category === FieldCategory.basic) {
if (field.isArray) {
write(" this." + member + " = decodeArray(stream, decode" + field.fieldType + ");");
} else {
if (false) {
write(" this." + member + ".decode(stream);");
} else {
if (_.isFunction(field.decode)) {
write(" this." + member + " = " + "schema" + ".fields[" + i + "].decode(stream);");
} else {
write(" this." + member + " = decode" + field.fieldType + "(stream);");
}
}
}
} else {
assert(field.category === FieldCategory.complex);
if (field.isArray) {
write(" this." + member + " = decodeArray(stream, (stream1: BinaryStream) => {");
write(" const obj = new " + field.fieldType + "();");
write(" obj.decode(stream1);");
write(" return obj;");
write(" });");
} else {
write(" this." + member + ".decode(stream);");
// xx write(" this." + member + ".decode(stream);");
}
}
}
示例10: createSession
/**
* @internal
* @param args
*/
public createSession(...args: any[]): any {
if (args.length === 1) {
return this.createSession({ type: UserTokenType.Anonymous }, args[0]);
}
const userIdentityInfo = args[0];
const callback = args[1];
this.userIdentityInfo = userIdentityInfo;
assert(_.isFunction(callback));
this._createSession((err: Error | null, session?: ClientSession) => {
if (err) {
callback(err);
} else {
if (!session) {
return callback(new Error("Internal Error"));
}
this._addSession(session as ClientSessionImpl);
this._activateSession(session as ClientSessionImpl,
(err1: Error | null, session2?: ClientSessionImpl) => {
callback(err1, session2);
});
}
});
}