Eliminate Prop-Drilling by Providing Ephemeral Services based on the route!
Supports Ember.js v3.4 or above
Q: How is this different from Ember's Services?
A: Three differences:
Q: Do the contextual services need to live in a specific location?
A: No, but co-location is highly encouraged. One of the main benefits to using contextual services over app-wide services is that usage can be reflected by the location of the file.
ember install ember-contextual-services--alpha
All ContextualServices are classes that can hold any state or perform any action. They could represent specific interfaces to APIs, or a way of accessing data loaded from ember-data from deep within the route's component tree.
NOTE: all of these examples are available for viewing in the tests/dummy
folder.
in routes/wherever/-contexts/local-service.js;
import { ContextualService } from 'ember-contextual-services';
import { inject as service } from '@ember/service';
import { tracked } from '@glimmer/tracking';
import { action } from '@ember/object';
export class LocalService extends ContextualService {
@service router;
@tracked foo = 0;
@action incrementFoo() {
this.foo++;
}
}
in routes/wherever/some-route.js
import Route from '@ember/routing/route';
import { withContextualServices } from 'ember-contextual-services';
import { LocalService } from './-contexts/local-service';
@withContextualServices(LocalService)
export default class SomeRoute extends Route {
}
or if you want to utilize the route's model hook for data-loading, you could do:
@withContextualServices(PersonService)
export default class SomeRoute extends Route {
@context(PersonService) personService;
async model() {
let response = await fetch('https://swapi.co/api/people/1/');
let json = await response.json();
this.personService.data = json;
}
}
and finally, in a component that is rendered by your route's template or a tree of components fromy our route's template,
import Component from '@glimmer/component';
import { context } from 'ember-contextual-services';
import { LocalService } from 'my-app/routes/whatever/-contexts/local-service';
export default class ServiceConsumer extends Component {
@context(LocalService) localService;
}
See the Contributing guide for details.
This project is licensed under the MIT License.
使 用 Hibernate 的大多数应用程序需要某种形式的“上下文相关的”会话,特定的会话在整个特定的上下文范围内始终有效。然而,对不同类型的应用程序而言,要为什么是组成这 种“上下文”下一个定义通常是困难的;不同的上下文对“当前”这个概念定义了不同的范围。在 3.0 版本之前,使用 Hibernate 的程序要么采用自行编写的基于 ThreadLocal 的上下文会话,要么采用 Hibernat
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-browser-services ember-browser-services is a collection of Ember Services that allow forconsistent interaction with browser APIs. When all browser APIs are accessed via services, browser behavio
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