A simple Ember.js addon to capture and expose the loading state of your app,so you can show that to the user with e.g. a loading indicator.
But Ember has loading substatesso why do I even need it?
This is true, and works basically like this: when the user transitions from/foo
to /bar
, the DOM previously rendered through foo.hbs
will be removed,the loading.hbs
template renders while loading of the bar
route is in progress,after which bar.hbs
is rendered. That's fine, if it is what you need.
But another UX approach would be to keep foo.hbs
rendered and add any kind ofloading indicator on top of it (e.g. an overlay over the existing content) orsomewhere else on the page while loading, and replace the rendered foo.hbs
with bar.hbs
only when loading has finished.
What else?
This addon helps you also to show the loading state for async processesbesides transitioning between routes, e.g. when you load or save data in acontroller/component.
How does it look like?
It is completely agnostic of any looks. It merely provides some basicinfrastructure to capture and expose the loading state. To actually renderyour loading indicator, you can use your own custom styled component or any ofthe existing loading indicator addons.
ember install ember-loading
The addon's central piece is the loading
service, which captures and exposesthe app's loading state.
The loading
service exposes the following properties, which you can use torender your loading indicator in any way:
Property | Description |
---|---|
isLoading: Boolean |
Will be true if any captured async processes (see below) are pending. |
showLoading: Boolean |
Will be true based on isLoading , but will take optional preDelay and postDelay into account, to optimize for the visual appearance. See Configuration below. |
while-loading
Rather than explicitly injecting the loading
service and using an {{#if}}
block in your template, you can more conveniently use the while-loading
component to wrap any content that should be shown only while loading:
The service will automatically recognize route transitions (i.e. async modelhooks) and set the service's loading state accordingly.
Whenever you kick off async processes that you want to show to the user, andwhich are not part of any of a route's model hooks, you can use the service'srun()
function, which will call your own async function, and set theservices's loading properties accordingly.
import Controller from '@ember/controller';
import { inject as service } from '@ember/service';
export default Controller.extend({
loading: service(),
actions: {
save(model) {
return this.loading.run(() => model.save());
}
}
})
The run()
method has the following signature, similar to many of Ember'srunloop functions:
Arguments / Return value | Description |
---|---|
target: any |
optional target of method to call |
method: Function|string |
Async method to invoke. May be a function or a string. If you pass a string then it will be looked up on the passed target. |
...args: any[] |
Any additional arguments you wish to pass to the function. |
returns | Promise that resolves with the return value of the invoked function. |
If you use native classes and decorators, you can use the supplied @loading
decorator to wrap any native method.
The decorator uses stage 1 syntax, meant to be used with TypeScript and/or
ember-cli-babel
V7.7.0+
import Controller from '@ember/controller';
import { action } from '@ember-decorators/object';
import { loading } from 'ember-loading';
export default class Foo extends Controller {
@action
@loading
save(model) {
return model.save();
}
}
The addon supports the following configuration options in your config/environment.js
, under theember-loading
key:
option | Default | Description |
---|---|---|
preDelay: number |
0 |
Amount of milliseconds to delay the showLoading property (see above) going from false to true. This allows you to suppress the loading indicator appearing for very short loading times. |
postDelay: number |
0 |
Amount of milliseconds to delay the showLoading property (see above) going from true to false. This can help you with aggregating multiple async processes happening in succession, to prevent flickering of the loading indicator. |
watchTransitions: Boolean |
true |
If false , async transitions do not affect the isLoading property. |
See the Contributing guide for details.
This project is licensed under the MIT License.
除了在上节中描述的技术,Ember路由器通过使用error和loading substates为自定义异步跳转提供强大而可重写的约定。 一、loading Substates 1. 在跳转过程中,Ember路由器允许你从各种各样的beforeModel/model/afterModel hooks中返回promises。这些promises暂停跳转直到它们被执行,此时跳转会恢复。 2. 考虑下面的
英文原版:https://guides.emberjs.com/v2.13.0/routing/loading-and-error-substates/ Ember Router允许你提供一个读取数据时的反馈–loading状态,同样也提供了error状态。 loading 子状态 在beforeModel,model和afterModel钩子函数的执行过程中,数据同时也是需要通过消耗一些时间来读
ember-teach Ember Teach博客文章md文件。网址:http://xcoding.tech/tags/Emberjs/ 目录 第一章 对象模型 类的定义、初始化、继承 类的扩展(reopen) 计算属性(compute properties) 观察者(observer) 绑定(bingding) 枚举(enumerables) 对象模型小结 第二章 模板 handlebars基础
此文中讲到的ember-data已经是老版本,不推荐大家使用了。 由于是从word考过来的,格式不是太好,大家可以直接去下载我的完整word。里面除了翻译还有原创内容。 http://download.csdn.net/detail/kevinwon1985/5230326 在大多数Ember应用中,模型都通过Ember Data处理。Ember Data是一个专门用于框架的库。它设计目的是方便的
Ember项目的入手 1.Emberjs项目采用两种不同的文件组织方式 1)功能类型组织:称作classic加粗样式 2)按照路由定义划分称作 pod 3)Classic的表现方式helpers,initializers,instance-initializers,mixns等。 4)Pod的表现形式:application,loading,not-found,pod。其他的可以查看app/rou
Ember.js 是什么?我想对于想学习它的人应该知道它是个什么东西,如果你想了解那就赶紧去 Google 或者百度,本系列教程是通过学习官网教程然后摘抄个人觉得比较重要的部分,加上学习实例整合而成,如有疏漏欢迎提出修改意见,一起成长! Ember官网:http://emberjs.com/ 教程官网:http://guides.emberjs.com/v2.0.0/
Ember检查器是一个浏览器插件,用于调试Ember应用程序。 灰烬检查员包括以下主题 - S.No. 灰烬检查员方式和描述 1 安装Inspector 您可以安装Ember检查器来调试您的应用程序。 2 Object Inspector Ember检查器允许与Ember对象进行交互。 3 The View Tree 视图树提供应用程序的当前状态。 4 检查路由,数据选项卡和库信息 您可以看到检查
英文原文: http://emberjs.com/guides/getting-ember/index/ Ember构建 Ember的发布管理团队针对Ember和Ember Data维护了不同的发布方法。 频道 最新的Ember和Ember Data的 Release,Beta 和 Canary 构建可以在这里找到。每一个频道都提供了一个开发版、最小化版和生产版。更多关于不同频道的信息可以查看博客
ember-emojione ember-emojione is your emoji solution for Ember, based on the EmojiOne project. EmojiOne version 2 is used, which is free to use for everyone (CC BY-SA 4.0), you're only required to giv
Ember 3D Ember 3D is an Ember addon for using Three.js - an easy to use, lightweight, javascript 3D library. It is designed to: Prescribe a solid file structure to Three.js code using ES6 modules. Ena
Ember Table An addon to support large data set and a number of features around table. Ember Table canhandle over 100,000 rows without any rendering or performance issues. Ember Table 3.x supports: Emb
vscode-ember This is the VSCode extension to use the Ember Language Server. Features All features currently only work in Ember-CLI apps that use classic structure and are a rough first draft with a lo