tnfe / limu

High performance immutable lib alternative to immer with the same api, based on shallow copy on read and mark modified on write mechanism.
https://tnfe.github.io/limu
MIT License
220 stars 13 forks source link

支持promise返回值 #5

Closed geekact closed 2 years ago

geekact commented 2 years ago

根据源码,limu判断produce的回调是否异步是通过isPromiseFn来判断。这只能支持async function() {}的写法,因此未考虑到用户写的是普通函数,最后返回的却是Promise实例的场景。

const result = produce(obj, (draft) => {
  return Promise.resolve().then(...);
});

因此建议参考immer https://github.com/immerjs/immer/blob/master/src/core/immerClass.ts#L101 ,替换掉isPromiseFn

fantasticsoul commented 2 years ago

收到建议,感谢你的反馈,修复后会在此在此答复

fantasticsoul commented 2 years ago

已支持,见版本1.3.0