@abadi199/remotedata 中文文档教程

发布于 6年前 浏览 26 项目主页 更新于 3年前

RemoteData for TypeScript

灵感来自 Kris Jenkin 的 Elm RemoteData 包和他的博客文章: http://blog.jenkster.com/2016/06/how-elm-slays-a-ui-antipattern.html

Example

function renderFruits(RemoteData<string[], string> fruits) {
    switch (fruits.kind) {
      case RemoteDataKind.Loading:
        renderLoading();
        break;
      case RemoteDataKind.Error:
        renderError(fruits.error);
        break;
      case RemoteDataKind.ErrorWithData:
        renderErrorWithData(fruits.value, fruits.error);
        break;
      case RemoteDataKind.NotAsked:
        clear();
        break;
      case RemoteDataKind.Reloading:
        renderReloading(fruits.value);
        break;
      case RemoteDataKind.Success:
        renderSuccess(fruits.value);
        break;
    }
} 

function main() {
    renderFruits(success(["Apple", "Orange", "Mango"])); // Success
    renderFruits(loading()); // Loading
    renderFruits(error("Error loading fruits")); // Error
    renderFruits(loading(success(["Apple", "Orange", "Mango"])); // Reloading
    renderFruits(error("", success(["Apple", "Orange", "Mango"]))); // ErrorWithData
}

Install

npm install -S @abadi199/remotedata

Contributing

  • Submit a pull request! If you're missing a feature you want to have, or just found a bug, or found an error in the docs, please submit a pull request.
  • Create an issue! If you found a bug or want a new feature that you think will make the library better, but don't have time to do it yourself, please submit an issue.

RemoteData for TypeScript

Inspired by Kris Jenkin's Elm RemoteData package and his blog post: http://blog.jenkster.com/2016/06/how-elm-slays-a-ui-antipattern.html

Example

function renderFruits(RemoteData<string[], string> fruits) {
    switch (fruits.kind) {
      case RemoteDataKind.Loading:
        renderLoading();
        break;
      case RemoteDataKind.Error:
        renderError(fruits.error);
        break;
      case RemoteDataKind.ErrorWithData:
        renderErrorWithData(fruits.value, fruits.error);
        break;
      case RemoteDataKind.NotAsked:
        clear();
        break;
      case RemoteDataKind.Reloading:
        renderReloading(fruits.value);
        break;
      case RemoteDataKind.Success:
        renderSuccess(fruits.value);
        break;
    }
} 

function main() {
    renderFruits(success(["Apple", "Orange", "Mango"])); // Success
    renderFruits(loading()); // Loading
    renderFruits(error("Error loading fruits")); // Error
    renderFruits(loading(success(["Apple", "Orange", "Mango"])); // Reloading
    renderFruits(error("", success(["Apple", "Orange", "Mango"]))); // ErrorWithData
}

Install

npm install -S @abadi199/remotedata

Contributing

  • Submit a pull request! If you're missing a feature you want to have, or just found a bug, or found an error in the docs, please submit a pull request.
  • Create an issue! If you found a bug or want a new feature that you think will make the library better, but don't have time to do it yourself, please submit an issue.
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文