本文整理匯總了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;
};
};