Skip to content

WWQ1993/apiAdapter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

api-adapt

功能

  • 重索引
  • 重赋值
  • 并发请求

安装


npm install api-adapt

使用

创建adapter实例

  1. 单一请求

const adapter = new Adapter(promise);
  1. 并行请求

const adapter = new Adapter({
    name1: promise1,
    name2: promise2
});

promise1:Promise,promise实例

promise2:Promise,promise实例

移除索引


adapter.remove(pathArray)

pathArray:Array,参见pathArray

重新索引


adapter.index([
    {
        toPath: path,
        fromPath: path,
        move: true  // 可选
    }
])

toPath:path,目标path

fromPath:path,源path

move:Boolean, 是否删除源path

修改/创建值


adapter.value([
   {
       path: path,
       value: newValue
   },
   {
       path: path,
       callback(oldValue) {   // 可选
           return newValue;
       }
   }
])

path:path,值的path value: 新值 callback:function,修改值时可选的回调函数,参数为原值,返回新值

pathArray

pathArray:Array,path数组

path:path, 参见path

path

path:String, 对象键名以.连接而成, 例如:


{
    a: {
        b: [
            c: 1234
        ]
    }
}

c的path为:a.b.0.c

更新日志

  • [3.0.0] DataAdapter去Promise化
  • [2.2.0] index: from/to; value: to
  • [2.1.3] DataAdapter可传入rules作为第二个参数
  • [2.1.2] Feature: DataAdapter
  • [2.1.1] callback
  • [2.1.0] 添加catch方法
  • [2.0.1] 进行UMD封装
  • [2.0.0] 修改调用方法名称
  • [1.1.0] 添加数组处理
  • [1.0.0] 初始化

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published