我正在制作一个将函数作为范围参数(scope: { method:'&theFunction' })的指令.我需要知道该方法返回的结果是否是一个有角度的承诺(如果有的话会在分辨率上发生,否则会立即发生).
现在我正在测试是否foo.then存在,但我想知道是否有更好的方法来做到这一点.
我正在尝试使用ngrx-store-localstorage将ngrx集成到我的身份验证过程中,以跨越浏览器会话存储令牌.
当我登录时,我可以在存储中看到令牌的价值
{"token":{"token":"e5cb6515-149c-44df-88d1-4ff16ff4169b","expiresIn":10385,"expiresAt":1512082478397},"authenticated":true,"error":false}
Run Code Online (Sandbox Code Playgroud)
但是当我编辑一个页面并重新加载我的应用程序时
{"token":null,"authenticated":false,"error":false}
Run Code Online (Sandbox Code Playgroud)
import { Action } from '@ngrx/store';
import { AuthenticationTokenInterface } from '../authentication.interface';
export const LOGIN = 'LOGIN';
export const LOGIN_SUCCESS = 'LOGIN_SUCCESS';
export const LOGIN_FAILED = 'LOGIN_FAILED';
export const LOGOUT = 'LOGOUT';
export const SET_TOKEN = 'SET_TOKEN';
export class Login implements Action {
readonly type = LOGIN;
constructor(public payload: {username: 'string',password: 'string'}) {}
}
export class LoginSuccess implements Action {
readonly type = LOGIN_SUCCESS;
}
export class LoginFailed implements Action {
readonly type = …Run Code Online (Sandbox Code Playgroud) 我试图使用OpenCover(今天下载)来覆盖我的测试.这是我用过的命令行:
OpenCover.Console.exe -target:"c:\Programmes2\xunit\xunit.console.clr4.x86.exe" -targetargs:"""C:\Sources\Project\BackOffice.Tests\bin\Debug\BackOffice.Tests.dll"" /noshadow " -output:bo.coverage.xml -targetdir:"C:\Sources\Project\BackOffice.Tests\bin\Debug" -filter:+[*]*
Run Code Online (Sandbox Code Playgroud)
这是我得到的输出
xUnit.net console test runner (32-bit .NET 4.0.30319.269)
Copyright (C) 2007-11 Microsoft Corporation.
xunit.dll: Version 1.9.0.1566
Test assembly: C:\Sources\Project\BackOffice.Tests\bin\Debug\BackOffice.Tests.dll
31 total, 0 failed, 0 skipped, took 2.760 seconds
Committing...
No results - no assemblies that matched the supplied filter were instrumented
this could be due to missing PDBs for the assemblies that match the filter
please review the output file and refer to the Usage guide (Usage.rtf)
Run Code Online (Sandbox Code Playgroud)
生成的报告始终相同:
<?xml version="1.0" encoding="utf-8"?> …Run Code Online (Sandbox Code Playgroud) 当我为所有页面提供共同属性时,我一直在努力寻找一种处理Asp.net MVC网站模型的好方法.这些属性将显示在布局(母版页)中.我正在使用一个包含这些属性的"BaseModel"类,我的布局使用此BaseModel作为其模型.
每个其他模型都继承自该BaseModel,并且每个模型都具有相对于它所代表的视图的特定属性.正如您可能已经猜到的那样,我的模型实际上是视图模型,即使这与此处不太相关.
我尝试了不同的方法来初始化BaseModel值
但这些都没有真正吸引我:
当然,(几乎)所有这些解决方案都有效,但我正在寻找一种更好的方法.
在输入这个问题时,我发现可能是一条新路径,也可能是构建器模式,但实现也很快成为负担,因为我们可以拥有数十个视图和控制器.
我很乐意接受任何严肃的建议/暗示/建议/模式/建议!
更新
感谢@EBarr我想出了另一个解决方案,使用ActionFilterAttribute(不是生产代码,在5分钟内完成):
public class ModelAttribute : ActionFilterAttribute
{
public Type ModelType { get; private set; }
public ModelAttribute(string typeName) : this(Type.GetType(typeName)) { }
public ModelAttribute(Type modelType)
{
if(modelType == null) { throw new ArgumentNullException("modelType"); }
ModelType = modelType;
if (!typeof(BaseModel).IsAssignableFrom(ModelType))
{
throw new ArgumentException("model type should inherit BaseModel");
}
}
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
var model = ModelFactory.GetModel(ModelType); …Run Code Online (Sandbox Code Playgroud) 当我看到这个(编辑)时,我正在查看docutil源代码(在python中):
def __init__(self, **attributes):
for att, value in attributes.items():
att = att.lower()
if att in self.list_attributes:
# mutable list; make a copy for this node
self.attributes[att] = value[:]
else:
self.attributes[att] = value
Run Code Online (Sandbox Code Playgroud)
我正在谈论的是这一行:
self.attributes[att] = value[:]
Run Code Online (Sandbox Code Playgroud)
"[:]"究竟做了什么?它上面的评论提示某种副本,但我的谷歌搜索并没有那么成功,我无法确定它是语言功能还是某种特技/快捷方式.
我正在尝试运行命令“npx react-native start”并显示此错误
error Cannot find module '@expo/metro-config'
Require stack:
- D:\Projetos\apporto\metro.config.js
- D:\Projetos\apporto\node_modules\cosmiconfig\node_modules\import-fresh\index.js
- D:\Projetos\apporto\node_modules\cosmiconfig\dist\loaders.js
- D:\Projetos\apporto\node_modules\cosmiconfig\dist\createExplorer.js
- D:\Projetos\apporto\node_modules\cosmiconfig\dist\index.js
- D:\Projetos\apporto\node_modules\@react-native-community\cli\build\tools\config\readConfigFromDisk.js
- D:\Projetos\apporto\node_modules\@react-native-community\cli\build\tools\config\index.js
- D:\Projetos\apporto\node_modules\@react-native-community\cli\build\commands\install\install.js
- D:\Projetos\apporto\node_modules\@react-native-community\cli\build\commands\index.js
- D:\Projetos\apporto\node_modules\@react-native-community\cli\build\index.js
- D:\Projetos\apporto\node_modules\@react-native-community\cli\build\bin.js
Error: Cannot find module '@expo/metro-config'
Require stack:
- D:\Projetos\apporto\metro.config.js
- D:\Projetos\apporto\node_modules\cosmiconfig\node_modules\import-fresh\index.js
- D:\Projetos\apporto\node_modules\cosmiconfig\dist\loaders.js
- D:\Projetos\apporto\node_modules\cosmiconfig\dist\createExplorer.js
- D:\Projetos\apporto\node_modules\cosmiconfig\dist\index.js
- D:\Projetos\apporto\node_modules\@react-native-community\cli\build\tools\config\readConfigFromDisk.js
- D:\Projetos\apporto\node_modules\@react-native-community\cli\build\tools\config\index.js
- D:\Projetos\apporto\node_modules\@react-native-community\cli\build\commands\install\install.js
- D:\Projetos\apporto\node_modules\@react-native-community\cli\build\commands\index.js
- D:\Projetos\apporto\node_modules\@react-native-community\cli\build\index.js
- D:\Projetos\apporto\node_modules\@react-native-community\cli\build\bin.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:924:15)
at Function.Module._load (node:internal/modules/cjs/loader:769:27)
at Module.require (node:internal/modules/cjs/loader:996:19)
at require (node:internal/modules/cjs/helpers:92:18)
at Object.<anonymous> (D:\Projetos\apporto\metro.config.js:1:30)
at Module._compile (node:internal/modules/cjs/loader:1092:14)
at …Run Code Online (Sandbox Code Playgroud) angular ×1
angularjs ×1
asp.net-mvc ×1
docutils ×1
ngrx ×1
node.js ×1
opencover ×1
python ×1
react-native ×1
xunit ×1