Merge pull request #26693 from deepfunc/master

seamless-immutable add method: 'replace' definition
This commit is contained in:
Nathan Shively-Sanders
2018-06-20 09:31:15 -07:00
committed by GitHub
2 changed files with 18 additions and 0 deletions

View File

@@ -18,6 +18,10 @@ declare namespace SeamlessImmutable {
merger?(a: any, b: any, config: any): any;
}
interface ReplaceConfig {
deep: boolean;
}
interface Options {
prototype?: any;
}
@@ -75,6 +79,8 @@ declare namespace SeamlessImmutable {
without<K extends keyof T>(property: K): ImmutableObject<T>;
without<K extends keyof T>(...properties: K[]): ImmutableObject<T>;
without<K extends keyof T>(filter: (value: T[K], key: K) => boolean): ImmutableObject<T>;
replace<S>(valueObj: S, options?: ReplaceConfig): ImmutableObject<S>;
}
interface ImmutableArrayMixin<T> {
@@ -92,6 +98,8 @@ declare namespace SeamlessImmutable {
function isImmutable(target: any): boolean;
function ImmutableError(message: string): Error;
function replace<T, S>(obj: ImmutableObject<T>, valueObj: S, options?: ReplaceConfig): ImmutableObject<S>;
}
declare function SeamlessImmutable<T>(obj: T[], options?: SeamlessImmutable.Options): SeamlessImmutable.ImmutableArray<T>;

View File

@@ -44,6 +44,12 @@ interface ExtendedUser extends User {
{
const isImmutable: boolean = Immutable.isImmutable(Immutable.from([0, 2]));
const user1: Immutable.ImmutableObject<User> = Immutable.from({
firstName: 'Angry',
lastName: 'Monkey'
});
const replacedUser01 = Immutable.replace(user1, { firstName: 'Super', lastName: 'Monkey' });
const replacedUser02 = Immutable.replace(user1, { firstName: 'Super', lastName: 'Monkey' }, { deep: true });
}
//
@@ -124,4 +130,8 @@ interface ExtendedUser extends User {
const firstNameWithDynamicPathWithDefault = immutableUser.getIn(['first' + 'name'], '');
const line1WithoutDefault = immutableUserEx.getIn(['address', 'line1']);
const line1WithDefault = immutableUserEx.getIn(['address', 'line1'], '');
// replace
const replacedUser01 = immutableUser.replace({ firstName: 'Super', lastName: 'Monkey' });
const replacedUser02 = immutableUser.replace({ firstName: 'Super', lastName: 'Monkey' }, { deep: true });
}