我在我的页面中嵌入了一个PDF,并且我想设置类似javascript-callback的东西,只要用户点击PDF中的链接就可以调用它.
有没有办法实现这个目标?
我一直在玩ES6和角度,我eslint-plugin-angular用来验证我的javascript.我有以下服务:
export function runBlock ($rootScope, $state, $log) {
'ngInject';
$rootScope.$on( '$stateChangeStart', function(event, toState) {
// ...
} );
Run Code Online (Sandbox Code Playgroud)
但是eslint给我以下错误:
The "$on" call should be assigned to a variable, in order to be
destroyed during the $destroy event
Run Code Online (Sandbox Code Playgroud)
我的意思是我理解这个警告,但是我在以前的角度项目中从未这样做过,如果我做了错误建议的话?为什么需要/良好实践?
这篇文章可供eslint-plugin-angular参考John Papa的角度风格指南,但我并没有真正提到这种情况.
简而言之,有没有办法定义一个包含另一个任意类型的消息的protobuf消息?就像是:
message OuterMsg {
required int32 type = 1;
required Message nestedMsg = 2; //Any sort of message can go here
}
Run Code Online (Sandbox Code Playgroud)
我怀疑有一种方法可以做到这一点,因为在各种protobuf实现中,编译的消息从一个公共Message基类扩展.
否则我想我必须为各种类型的消息创建一个公共基本消息,如下所示:
message BaseNestedMessage {
extensions 1 to max;
}
Run Code Online (Sandbox Code Playgroud)
然后呢
message OuterMessage {
required int32 type = 1;
required BaseNestedMessage nestedMsg = 2;
}
Run Code Online (Sandbox Code Playgroud)
这是实现这一目标的唯一途径吗?
如何处理嵌套中的第三方依赖项(即不以嵌套模块形式出现的依赖项)的最佳实践是什么?
例如,我通过morgan在各自的文件中导入它直接在我自己的日志记录模块中使用它:
import { Injectable, MiddlewareFunction, NestMiddleware } from '@nestjs/common';
import * as morgan from 'morgan';
@Injectable()
export class NestLoggingMiddleware implements NestMiddleware {
resolve(...args: any[]): MiddlewareFunction {
/** use morgan here, e.g. wrap it in a custom middleware ... */
}
}
Run Code Online (Sandbox Code Playgroud)
现在我知道 nest 的架构深受 Angular 的影响,我发现这篇文章解释了如何处理 angular 中的 3rd 方依赖关系。同样的想法也适用于嵌套吗?我应该为它创建一个自定义提供程序morgan并注入它吗?我是只注入morgan导入还是已配置的morgan实例?
我正在使用Eclipse开发Eclipse SWT应用程序.还有一些JUnit 4测试,测试一些DAO.但是当我尝试通过ant构建运行测试时,所有测试都失败了,因为找不到测试类.
谷歌带来了大约一百万人都有同样的问题,但他们的解决方案似乎都不适合我 - .-.
这些是我的build.xml文件的内容:
<property name="test.reports" value="./test/reports" />
<property name="classes" value="build" />
<path id="project.classpath">
<pathelement location="${classes}" />
</path>
<target name="testreport">
<mkdir dir="${test.reports}" />
<junit fork="yes" printsummary="no" haltonfailure="no">
<batchtest fork="yes" todir="${test.reports}" >
<fileset dir="${classes}">
<include name="**/Test*.class" />
</fileset>
</batchtest>
<formatter type="xml" />
<classpath refid="project.classpath" />
</junit>
<junitreport todir="${test.reports}">
<fileset dir="${test.reports}">
<include name="TEST-*.xml" />
</fileset>
<report todir="${test.reports}" />
</junitreport>
</target>
Run Code Online (Sandbox Code Playgroud)
测试类与应用程序类一起位于build-directory中,尽管它们根据其包在某些子文件夹中.
也许这也很重要:首先,Ant抱怨JUnit不在其类路径中,但是因为我把它放在那里(使用eclipse配置编辑器),它抱怨JUnit在其类路径中两次.
WARNING: multiple versions of ant detected in path for junit
[junit] jar:file:C:/Users/as df/Documents/eclipse/plugins/org.apache.ant_1.7.1.v20090120-1145/lib/ant.jar!/org/apache/tools/ant/Project.class
[junit] and jar:file:/C:/Users/as%20df/Documents/eclipse/plugins/org.apache.ant_1.7.1.v20090120-1145/lib/ant.jar!/org/apache/tools/ant/Project.class
Run Code Online (Sandbox Code Playgroud)
我已经尝试指定每个子目录,每个类文件,我已经尝试过文件集和文件列表,似乎没什么用. …
我有以下JS代码片段:
var source = new EventSource( "http://localhost:8081/resources" );
source.onmessage = function() {
console.log( "Event received!" );
};
source.onerror = function( error ) {
console.log( "Eventsource error" );
console.log( error );
};
source.open = function() {
console.log( "Eventsource open" );
};
Run Code Online (Sandbox Code Playgroud)
我的服务器一次发出了一个简单的测试事件。在chrome的“网络”标签中,我看到事件以的形式出现text/event-stream,状态代码为200。不过,我的onmessage回调不会被调用。相反,我得到了onerror回调,但没有很多有用的错误信息。
令我感到困惑的另一件事是,Chrome似乎每3秒左右重新请求一次该事件。我在服务器上看到日志输出,提示该错误事件每3秒发生一次。
如果有帮助,则所有这些都在CORS场景中进行。
Firefox中也发生了同样的情况,只是我看不到“网络”选项卡中的请求,我认为Firefox只是不在那里显示SSE事件。
我正在尝试使用来自REST API 的出色request.el库请求数据:
(request
"http://httpbin.org/get"
:params '(("key" . "value") ("key2" . "value2"))
:parser 'json-read
:success (function*
(lambda (&key data &allow-other-keys)
(message "I sent: %S" (assoc-default 'args data)))))
Run Code Online (Sandbox Code Playgroud)
哪个很好。作为一个新手,我真的不知道在function*这里做什么,我只是从request.el-examples 那里得到的。
然后,我尝试将此调用包装到一个函数中以减少样板,如下所示:
(defun my/do-request (callback)
(request
"http://httpbin.org/get"
:params '(("key" . "value") ("key2" . "value2"))
:parser 'json-read
:success callback))
(my/do-request (lambda (data)
(message "got data: %s" data)))
Run Code Online (Sandbox Code Playgroud)
但是回调没有被调用吗?我也尝试过像这样传递回调:
(defun my/do-request (callback)
(request
"http://httpbin.org/get"
:params '(("key" . "value") ("key2" . "value2"))
:parser 'json-read
:success (function*
(lambda (&key data …Run Code Online (Sandbox Code Playgroud) 我正在玩 ant-design 并尝试构建一个简单的菜单,一切都按预期工作:
<Menu mode="inline">
<Menu.Item key="/">
<Icon type="dashboard" theme="outlined" />
Dashboard
</Menu.Item>
<Menu.Item key="/transactions">
<Icon type="bars" theme="outlined" />
Transactions
</Menu.Item>
<Menu.Item key="/groups">
<Icon type="team" theme="outlined" />
Groups
</Menu.Item>
<Menu.Item key="/account">
<Icon type="idcard" theme="outlined" />
Account
</Menu.Item>
</Menu>
Run Code Online (Sandbox Code Playgroud)
( https://codesandbox.io/s/wqn37ojmv7 )
现在,我想通过制作一个单独的包装MenuItem组件来稍微整理一下这段代码:
const MenuItem = ({route, icon, children}) => (
<Menu.Item key={route}>
<Icon type={icon} theme="outlined" />
{children}
</Menu.Item>
);
// ...
<Menu mode="inline">
<MenuItem route="/" icon="dashboard">Dashboard</MenuItem>
<MenuItem route="/transactions" icon="bars">Transactions</MenuItem>
<MenuItem route="/groups" icon="team">Groups</MenuItem>
<MenuItem route="/account" icon="idcard">Account</MenuItem>
</Menu>
Run Code Online (Sandbox Code Playgroud)
然而,替换我闪亮的新组件几乎会破坏一切 - …
模块的官方嵌套文档解释了全局模块和动态模块。我想知道是否可以将这两种模式结合起来?
我的用例如下:我有一个动态配置模块:
export class ConfigModule {
static forRoot(baseConfigPath: string): DynamicModule {
const providers = [{ provide: 'Config', useValue: configFactory(baseConfigPath) }];
return {
module: ConfigModule,
providers,
exports: providers,
};
}
}
Run Code Online (Sandbox Code Playgroud)
这使配置模块能够依赖于传入的基本配置路径。然后我可以在主应用程序模块中导入模块,如下所示:
@Module({
imports: [ConfigModule.forRoot(path.resolve(__dirname, '../config'))],
controllers: [AppController],
providers: [AppService],
})
export class AppModule implements NestModule {}
Run Code Online (Sandbox Code Playgroud)
这很好。但是,我确实有很多其他模块(app 模块的子模块,配置模块的兄弟模块),我也希望动态配置模块的同一个实例是可注入的。如果我能ConfigModule以某种方式将动态标记为全局会很棒- 或者有另一种方式吗?
我已经尝试使用 制作ConfigModule全局@Global,但这不起作用 - 这是一个基于由nest new以下人员创建的 nest starter 的超级最小简化示例 repo :https : //github.com/DeX3/nest-di-playground
我需要在客户端动态加载dayjs区域设置。在服务器上,我可以只需要它并且它可以工作,但它总是会导致水合作用不匹配,因为客户端上没有办法等到
import(`dayjs/locale/${locale}.js`)
Run Code Online (Sandbox Code Playgroud)
实际上完成了。我可以以某种方式告诉 next 在开始在客户端上重新水化之前等待导入(因为服务器渲染的 html 实际上是正确的并且使用正确的区域设置渲染)?