首页 > 其他分享 >seamless-Immutable API(中文文档)

seamless-Immutable API(中文文档)

时间:2023-08-11 12:38:26浏览次数:48  
标签:console log seamless API let var obj Immutable

seamless-Immutable

  • seamless-Immutable是一套轻量级的持久化数据结构库 , seamless-immutable 并没有实现完整的 Persistent Data Structure 而是使用 Object.defineProperty(因此只能在 IE9 及以上使用)扩展了 JavaScript 的 Array 和 Object 对象来实现,只支持 Array 和 Object 两种数据类型,API 基于与 Array 和 Object 操持不变。代码库非常小,压缩后下载只有 2K。相比 Immutable.js 压缩后下载有 16K而言,小巧了很多, 而且API比较简洁,易懂

seamless-Immutable API汇总

from(type)
  • type:array | object
  • 设置成 Immutable 对象
let code1 = Immutable.from([1, 2, 3]);
let code2 = Immutable([1, 2, 3])); //同 from()
console.log(code1);//Immutable([1, 2, 3])
console.log(code2);//Immutable([1, 2, 3])
isImmutable(type)
  • type:array | object | immutable
  • 判断是否是 Immutable 对象
let code1=Immutable.from([1, 2, 3])
let code2= {a: 12};
console.log(Immutable.isImmutable(code1)); //true
console.log(Immutable.isImmutable(code2)); //false
  • 注:参数如果是 int string bool,undefined,null 返回 true
asMutable(obj,type)
  • obj: immutable
  • type:默认是{deep:false}
  • 返回数组的可变副本,对于深度可变的副本需设置 {deep:true}
code1:
var array = Immutable(['hello', 'world']);
var mutableArray = Immutable.asMutable(array);
console.log(array); //Immutable(['hello', 'world'])
console.log(mutableArray); //['hello', 'world']
code2:
var code1 = Immutable(['hello', 'world', ['immutable', 'react']]);
var code2 = Immutable.asMutable(code1, {deep: true});
console.log(code1); //Immutable(['hello', 'world',['immutable', 'react']])
console.log(code2); //['hello', 'world',['immutable', 'react']]
merge (obj1,obj2,type)
  • obj1 immutable
  • obj2 : object| array
  • type: object 默认是{deep:false}
  • 返回合并后的 Immutable,对于深度可变的副本需设置 {deep:true}
code1:
var obj = Immutable({a: 'AA', b: 'BB', c: 'CC'});
let newobj = Immutable.merge(obj, {c: 'CC', d: 'DD'});
console.log(newobj); // Immutable({a: "AA", b: "BB", c: "CC", d: "DD"})
code2:
var obj = Immutable({status: 'ok', data: {a: 'AA', b: 'BB'}});
let newsobj = Immutable.merge(obj, [{status: 'error', data: {c: 'CC'}}, {data: {a: 'AAAA'}}], {deep: true});
console.log(newsobj); //Immutable({status: "error", {a: "AAAA", b: "BB", c: "CC"}})
code3:
var code1 = Immutable([1, 2, 3]); //Array无效
let code2 = Immutable.merge(code1, [4, 5, 6]);
console.log(code2); //Immutable([1,2,3])
replace(obj1,obj2,type)
  • obj1 immutable
  • obj2 : object
  • type: object 默认是{deep:false}
  • 返回替换后的 Immutable,对于深度可变的副本需设置 {deep:true}
var obj1 = Immutable({a: {b: 'test'}, c: 'test'});
var obj2 = Immutable.replace(obj1, {a: {b: 'test'}, d: 'ok'}, {deep: true});
console.log(obj2);//Immutable({a: {b: 'test'}, d: 'ok'})
console.log(obj1 === obj2); //  false
console.log(obj1.a === obj2.a); //  true
set(obj,key,value,type)
  • obj1 immutable
  • key : string
  • value : any
  • type: object 默认是{deep:false}
  • 设置 immutable 对象制定的值
var obj = Immutable({a: 'AA', b: 'BB', c: {d: 'DD'}});
let newobj = Immutable.set(obj, 'b', 'BBB');
console.log(obj); // Immutable({a: 'AA', b: 'BB', c: {d: 'DD'}})
console.log(newobj); // Immutable({a: 'AA', b: 'BBB', c: {d: 'DD'}})
setIn (obj,key,value,type)
  • obj1 immutable
  • key : string
  • value : any
  • type: object 默认是{deep:false}
  • 深度设置 immutable 对象制定的值
var obj = Immutable({a: 'AA', b: 'BB', c: {d: 'DD'}});
let newobj = Immutable.setIn(obj, ['c', 'd'], 'DDDD');
console.log(obj);//Immutable({a: 'AA', b: 'BB', c: {d: 'DD'})
console.log(newobj); //Immutable({a: 'AA', b: 'BB', c: {d: 'DDDD'})
getIn(ob,arr,default)
  • obj: immutable
  • key : array
  • default : 如果返回值为空则返回默认值
  • 获取 immutable 对象指定的值
var obj = Immutable({a: {b: 'BB', c: 'CC'}, d: 'DD'});
let code1 = Immutable.getIn(obj, ['a', 'b']);
let code2 = Immutable.getIn(obj, ['a', 'c'], 'EE');
console.log(code1); //BB
console.log(code2); //CC
update(obj,key,fun,parmas)
  • obj: immutable
  • key : string
  • fun : function
  • parmas:any,回调函数的参数
  • 修改 immutable 对象的值
code1:
let fun = x => x + x;
var obj = Immutable({a: 'AA'});
let newobj = Immutable.update(obj, 'a', fun);
console.log(obj); //Immutable({a: 'AA'})
console.log(newobj); // Immutable({a: 'AAAA'})
code 2 :
let add = (x, y) => x + ' ' + y;
var obj = Immutable({a: 'hello'});
var newobj = Immutable.update(obj, 'a', add, 'world');
console.log(obj); //Immutable({a: 'hello'})
console.log(newobj); //Immutable({a: 'hello world'})
updateIn(obj,key,fun,parmas)
  • obj: immutable
  • key : array
  • fun : function
  • parmas:any,回调函数的参数
  • 深度修改 immutable 对象的值
let add = (x, y) => x + y;
var obj = Immutable({a: {b: 1}});
let newobj = Immutable.updateIn(obj, ['a', 'b'], add, 10);
console.log(obj);//Immutable({foo: {bar: 1}})
console.log(newobj); //Immutable({foo: {bar: 11}})
without(obj,key)
  • obj: immutable
  • key : array | string |function
  • 删除 immutable 对象的值
code 1:
var obj = Immutable({a: 'AA', b: 'BB', c: 'CC'});
let obj1 = Immutable.without(obj, 'b');
console.log(obj1); // Immutable({a: 'AA', c: 'CC'})
code 2:
var obj = Immutable({a: 'AA', b: 'BB', c: 'CC'});
let obj2 = Immutable.without(obj, ['a', 'b']);
console.log(obj2); // Immutable({ c: 'CC'})
code 3:
var obj = Immutable({a: 'AA', b: 'BB', c: 'CC'});
let obj3 = Immutable.without(obj, 'a', 'b');
console.log(obj3); // Immutable({ c: 'CC'})
code 4:
var obj = Immutable({a: 'AA', b: 'BB', c: 'CC'});
let obj4 = Immutable.without(obj, (value, key) => key === 'a' || value === 'BB');
console.log(obj4); // Immutable({ c: 'CC'})
flatMap(obj,fun)
  • obj: immutable
  • fun : function
  • 循环 immutable 对象, 返回 一个新的 immutable 对象
var array = Immutable(['AA', 'BB', 'CC']);
let newarr = Immutable.flatMap(array, str => 'hello ' + str);
console.log(newarr); //Immutable(["hello AA", "hello BB", "hello CC"])
asObject(obj,fun)
  • obj: immutable
  • fun : function
  • 迭代器函数将返回两个元素的数组 - 第一个表示键,另一个表示值。然后返回由这些键和值构成的不可变对象。
var array = Immutable(['aa', 'bb']);
let newobj = Immutable.asObject(array, str => {
    return [str, str.toUpperCase()];
});
console.log(newobj); //Immutable({aa: "AA", bb: "BB"})

标签:console,log,seamless,API,let,var,obj,Immutable
From: https://blog.51cto.com/u_11309339/7045822

相关文章

  • 文档控件DevExpress Office File API v23.1新版亮点 - 支持.NET MAUI
    DevExpressOfficeFileAPI是一个专为C#,VB.NET和ASP.NET等开发人员提供的非可视化.NET库。有了这个库,不用安装MicrosoftOffice,就可以完全自动处理Excel、Word等文档。开发人员使用一个非常易于操作的API就可以生成XLS,XLSx,DOC,DOCx,RTF,CSV和SnapReport等企业级文......
  • HarmonyOS/OpenHarmony应用开发-ArkTSAPI系统能力SystemCapability列表
    SysCap,全称SystemCapability,即系统能力,指操作系统中每一个相对独立的特性。开发者使用某个接口进行开发前,建议先阅读系统能力使用说明,了解Syscap的定义和使用指导。说明当前列表枚举出3.1Beta版本中支持的系统能力。开发者可以在SDK中通过phone.json文件查询。SystemCapability.Ar......
  • 如何使用原生 JavaScript Canvas API 实现视频中的绿幕背景替换功能 All In One
    如何使用原生JavaScriptCanvasAPI实现视频中的绿幕背景替换功能AllInOneCanvas&Videodemoschroma-keying/greenscreeneffectconstprocessor={};processor.doLoad=functiondoLoad(){constvideo=document.getElementById("video");this.vid......
  • 基于mediapipe的单人人体骨架细节提取
    MediaPipe是一款由GoogleResearch开发并开源的多媒体机器学习模型应用框架。在谷歌,一系列重要产品,如、GoogleLens、ARCore、GoogleHome以及,都已深度整合了MediaPipe。本文将介绍的为基于mediapipe的人体骨架提取方案。1、mediapipe的安装安装指令如下:pipinstallmed......
  • Apipost接口自动化中关联关系如何配置
    在接口自动化测试中,接口之间可能存在依赖关系,即某些接口的执行需要先完成其他接口的执行。为了确保测试用例的正确执行,我们需要在配置测试用例时考虑接口之间的依赖关系。在编写测试用例时,需要明确每个接口的功能和输入输出参数。根据接口之间的依赖关系,将测试用例按照执行顺序组......
  • K8S 1.27.1版本初始化配置文件时报your configuration file uses an old API spec: "k
    现象:yourconfigurationfileusesanoldAPIspec:"kubeadm.k8s.io/v1beta2".Pleaseusekubeadmv1.22insteadandrun'kubeadmconfigmigrate--old-configold.yaml--new-confignew.yaml',whichwillwritethenew,similarspecusingan......
  • Eolink 出席 QECon 大会,引领「AI+API」技术的革新浪潮
    7月28日-29日,第八届QECon质量效能大会在北京成功召开。大会聚焦“数生智慧,高质量发展新引擎”,深入探讨如何利用数字化和智能化技术推动软件质量的发展,进而为高质量的经济发展提供新的引擎。作为国内API全生命周期解决方案的领军者,Eolink受邀出席本次大会。会上,EolinkCEO......
  • 微信的 h5 支付和 jsapi 支付
    目录......
  • API 接口设计规范
    概述这篇文章分享API接口设计规范,目的是提供给研发人员做参考。规范是死的,人是活的,希望自己定的规范,不要被打脸。路由命名规范动作前缀备注获取getget{XXX}获取getget{XXX}List新增addadd{XXX}修改updateupdate{XXX}保存savesave{XXX}删除deletedelete{XXX}上传uploadupload{XXX}......
  • API 接口设计规范
     概述这篇文章分享API接口设计规范,目的是提供给研发人员做参考。规范是死的,人是活的,希望自己定的规范,不要被打脸。路由命名规范动作前缀备注获取getget{XXX}获取getget{XXX}List新增addadd{XXX}修改updateupdate{X......