首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何在我的插件中弃用一个功能?

如何在我的插件中弃用一个功能?
EN

Stack Overflow用户
提问于 2019-06-06 06:50:54
回答 1查看 79关注 0票数 0

我正在写一个Ember.js插件,我需要弃用一个特性。我可以使用和Ember相同的弃用系统吗?我希望我的用户能够使警告静默。

理想情况下,我还需要能够在我的测试套件中测试弃用消息是否在正确的条件下工作。

我使用的是Ember 3.x。

EN

回答 1

Stack Overflow用户

发布于 2019-06-06 06:50:54

通过deprecate方法,插件可以使用与Ember相同的弃用警告样式:

import { deprecate } from '@ember/application/deprecations';

deprecate有三个参数:作为消息的字符串、布尔测试( falsey表示将显示弃用信息)和一个包含更多信息的options对象。

例如:

import { deprecate } from '@ember/application/deprecations';
// ...
deprecate(
   "message about your addon that mentions the addon by name", 
   false,
   {
      id: 'send-component-hash',
      until: '2.0.0',
      url: 'some url goes here'
    }
);
// ...

控制台中的消息将如下所示:

可以使用像ember-qunit-assert这样的库来测试弃用。安装完成后,如果您已经在测试中使用了expectDeprecation,则可以在assert上使用qunit

assert.expectDeprecation(/expected deprecation message/);
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56469007

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档