本文整理汇总了TypeScript中Immutable.Record函数的典型用法代码示例。如果您正苦于以下问题:TypeScript Record函数的具体用法?TypeScript Record怎么用?TypeScript Record使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Record函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: it
it('supports imbricated Record {min: false}', () => {
const CDRecord = Immutable.Record({c: 3, d: 4}, 'CDRecord');
const ABRecord = Immutable.Record({a: CDRecord(), b: 2}, 'ABRecord');
expect(ABRecord()).toPrettyPrintTo(
'Immutable.ABRecord {\n "a": Immutable.CDRecord {\n "c": 3,\n "d": 4,\n },\n "b": 2,\n}',
);
});
示例2: it
it('passes through records of the same type', () => {
var P2 = Record({ x: 0, y: 0 });
var P3 = Record({ x: 0, y: 0, z: 0 });
var p2 = P2();
var p3 = P3();
expect(P3(p2) instanceof P3).toBe(true);
expect(P2(p3) instanceof P2).toBe(true);
expect(P2(p2)).toBe(p2);
expect(P3(p3)).toBe(p3);
})
示例3: describe
describe('shared / model-helper', () => {
interface Mock {
prop1: string;
prop2: string;
}
const MockModel: Record.Factory<Mock> = Record<Mock>({
prop1: '',
prop2: ''
});
describe('generateMap', () => {
const mockData: Mock[] = [
{ prop1: 'value10', prop2: 'value10' },
{ prop1: 'value11', prop2: 'value21' },
{ prop1: 'value12', prop2: 'value22' }
];
it('should return an Immutable Map', () => {
const expectedMap = Map([
[0, new MockModel(mockData[0])],
[1, new MockModel(mockData[1])],
[2, new MockModel(mockData[2])]
]);
expect(generateMap(mockData, MockModel).toObject()).to.deep.equal(expectedMap.toObject());
});
});
});
示例4: builds
export default function builds(state = initialState["builds"], action) {
switch (action.type) {
case actionTypes.CLEAR_BUILD:
return state
.setIn(["selected", "info"], Record({})());
case actionTypes.CLEAR_BUILD_LOG:
state.get("selected").log.content.next([]);
return state.setIn(["selected", "log"], {
start: undefined,
stop: undefined,
content: state.get("selected").log.content,
is_complete: undefined
});
case actionTypes.CLEAR_BUILDS:
return state
.setIn(["visible"], List());
case actionTypes.POPULATE_BUILD:
return state.setIn(["selected", "info"], action.payload);
case actionTypes.POPULATE_BUILD_LOG:
let payload = action.payload;
let content = state.get("selected").log.content;
// It'll be common to get log requests for builds that haven't
// started yet (which will surface as errors), so in that case,
// we'll just hand back the current state.
if (action.error) {
return state;
}
if (payload.start === 0 && !payload.is_complete) {
content.next(payload.content || []);
}
else if (payload.content.length) {
content.next(payload.content);
}
return state.setIn(["selected", "log"], {
start: payload.start,
stop: payload.stop,
content: content,
is_complete: payload.is_complete
});
case actionTypes.POPULATE_BUILDS:
return state.setIn(["visible"], List(action.payload));
case actionTypes.STREAM_BUILD_LOG:
return state.setIn(["selected", "stream"], action.payload);
default:
return state;
}
}
示例5: Record
export function makeTypedFactory<E, T extends TypedRecord<T> & E>
(obj: E, name?: string): (val?: E) => T {
const ImmutableRecord = Record(obj, name);
return function TypedFactory(val: E = null): T {
return new ImmutableRecord(val) as T;
};
};