本文整理汇总了TypeScript中src/utils.isObject函数的典型用法代码示例。如果您正苦于以下问题:TypeScript isObject函数的具体用法?TypeScript isObject怎么用?TypeScript isObject使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了isObject函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: stateUpdated
/**
* Invoked when the state updates.
*
* @param current - The current (most) game state, will be this.next if this.current is undefined.
* @param next - The next (most) game state, will be this.current if this.next is undefined.
* @param delta - The current (most) delta, which explains what happened.
* @param nextDelta - The the next (most) delta, which explains what happend.
*/
public stateUpdated(
current: Immutable<IUnitState>,
next: Immutable<IUnitState>,
delta: Immutable<Delta>,
nextDelta: Immutable<Delta>,
): void {
super.stateUpdated(current, next, delta, nextDelta);
// <<-- Creer-Merge: state-updated -->>
// update the Unit based off its states
this.attackingTile = undefined;
if (nextDelta.type === "ran" && nextDelta.data.run.caller.id === this.id) {
if (nextDelta.data.returned) {
const { run } = nextDelta.data;
const tile = this.game.gameObjects[String(
isObject(run.args.tile) && run.args.tile.id,
)];
switch (run.functionName) {
case "attack":
this.attackingTile = tile && (tile as Tile).getNextMostState();
}
}
}
// <<-- /Creer-Merge: state-updated -->>
}
示例2: deserialize
export function deserialize<T extends unknown>(data: T, game?: BaseGame): T {
if (isObject(data)) {
// TODO: check for game object reference?
const result: UnknownObject = Array.isArray(data) ? [] : {};
for (const key of (Object.keys(data))) {
result[key] = deserialize((data as UnknownObject)[key], game);
}
return result as T;
}
return data;
}
示例3: serialize
export function serialize(
data: unknown,
): string | number | { [key: string]: string | number } {
// Then no need to serialize it, it's already json serializable as a
// string, number, boolean, null, etc.
if (!isObject(data)) {
return data as string | number;
}
if (data.id) {
// No need to serialize this whole game object,
// just send an object reference
return { id: String(data.id) };
}
const serialized: UnknownObject = Array.isArray(data) ? [] : {};
for (const key of Object.keys(data)) {
if (isSerializable(data, key)) {
serialized[key] = serialize(data[key]);
}
}
return serialized as { [key: string]: string | number };
}
示例4: isSerializable
export function isSerializable(obj: object, key: string): boolean {
return isObject(obj) && objectHasProperty(obj, key);
}
示例5: requireGameResource
/** The expected interface all games must export from their interface. */
interface IGameExport {
/** The Namespace that contains all data to initiate a game from. */
namespace: IBaseGameNamespace;
}
// require all images in the build
/** Requires a resource in a game's resources directory. */
export const requireGameResource = require.context("./", true, /^(.*(\.(png|jpe?g)$))[^.]*$/im);
for (const key of requireGameResource.keys()) {
requireGameResource(key);
}
const games: {[gameName: string]: IBaseGameNamespace | undefined} = {};
const req = require.context("./", true, /\.\/([^\/]+)\/index.ts/); // match ./*/index.ts, but only 1 directory.
for (const key of req.keys()) {
const required = req(key) as IGameExport;
if (!required || !isObject(required) || !isObject(required.namespace)) {
throw new Error(`Game "${key}" does not export the expected interface!`);
}
const { namespace } = required;
if (namespace.Game) {
games[namespace.Game.gameName] = namespace;
}
}
/** All the game namespaces that can be loaded by this instance */
export const GAMES = Object.freeze(games);