v0.2 Controller.fetch、异步 getHeaders、Collection
· 阅读需 6 分钟
Collection 让数组和对象可以通过 push 或 unshift 新成员来轻松扩展。它的名字来自 Backbone Collections。
Collection 现在是 Resource.getList 的默认 schema。
TodoResource
TodoItem
CreateTodo
TodoList
import { useController } from '@data-client/react'; import { TodoResource } from './TodoResource'; export default function CreateTodo({ userId }: { userId: number }) { const ctrl = useController(); const handleKeyDown = async e => { if (e.key === 'Enter') { ctrl.fetch(TodoResource.getList.push, { userId, title: e.currentTarget.value, id: Math.random(), }); e.currentTarget.value = ''; } }; return ( <div className="listItem nogap"> <label> <input type="checkbox" name="new" checked={false} disabled /> <input type="text" onKeyDown={handleKeyDown} /> </label> </div> ); }
结果
升级相当简单,因为我们引入了 @data-client/rest/next 和 @data-client/react/next,以便渐进式地采用本版本中变更的新 API。这使得实际的升级只是简单地重命名一下导入路径。
其他亮点包括
@data-client/rest@data-client/react
完整细节请继续阅读:
