小编Seb*_* F.的帖子

有什么方法可以知道变量是否是angularjs的承诺?

我正在制作一个将函数作为范围参数(scope: { method:'&theFunction' })的指令.我需要知道该方法返回的结果是否是一个有角度的承诺(如果有的话会在分辨率上发生,否则会立即发生).

现在我正在测试是否foo.then存在,但我想知道是否有更好的方法来做到这一点.

angularjs

58
推荐指数
3
解决办法
2万
查看次数

angular ngrx-store-localstorage在重新加载后不存储数据

我正在尝试使用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)

authentication ngrx angular

11
推荐指数
1
解决办法
4315
查看次数

opencover + xunit没有结果

我试图使用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)

xunit opencover

9
推荐指数
1
解决办法
3471
查看次数

用于视图和布局的Asp.net MVC模型

当我为所有页面提供共同属性时,我一直在努力寻找一种处理Asp.net MVC网站模型的好方法.这些属性将显示在布局(母版页)中.我正在使用一个包含这些属性的"BaseModel"类,我的布局使用此BaseModel作为其模型.

每个其他模型都继承自该BaseModel,并且每个模型都具有相对于它所代表的视图的特定属性.正如您可能已经猜到的那样,我的模型实际上是视图模型,即使这与此处不太相关.

我尝试了不同的方法来初始化BaseModel值

  1. 在每个视图中都是"手"
  2. 有一个具有Initialize虚方法的基本控制器来执行它(因此特定控制器可以实现特定的常见行为)
  3. 有一个基础控制器覆盖OnActionExecuting以调用Initialize方法
  4. 使用辅助类在控制器外部执行
  5. 使用模型工厂

但这些都没有真正吸引我:

  1. 似乎很明显对我来说,却是干的一个原因足以证明那个(其实我从来没有试过这种解决方案在所有的,我只是把它能够循环在这一点上的最后一点).
  2. 我不喜欢那个,因为这意味着每当添加一个新的Controller时,你需要知道它必须从BaseController继承并且你需要调用Initialize方法,更不用说如果你的控制器已经覆盖了基础一,无论如何要调用基数来维持价值.
  3. 看下一点
  4. 3.是同一主题的变体,但对第二个解决方案的问题并没有真正的帮助.
  5. 到目前为止我最喜欢的,但现在我必须传递一些变量来设置这些值.我喜欢它的依赖倒置.不过,如果我想从会议提供价值,我要明确地传递他们为例,然后我又回到了起点,因为我有手,为他们提供(即引用或通过任何类型的接口)

当然,(几乎)所有这些解决方案都有效,但我正在寻找一种更好的方法.

在输入这个问题时,我发现可能是一条新路径,也可能是构建器模式,但实现也很快成为负担,因为我们可以拥有数十个视图和控制器.

我很乐意接受任何严肃的建议/暗示/建议/模式/建议!

更新

感谢@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)

asp.net-mvc

5
推荐指数
1
解决办法
2418
查看次数

Python字典"复制值"

当我看到这个(编辑)时,我正在查看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)

"[:]"究竟做了什么?它上面的评论提示某种副本,但我的谷歌搜索并没有那么成功,我无法确定它是语言功能还是某种特技/快捷方式.

python docutils

2
推荐指数
1
解决办法
336
查看次数

当我运行“npx react-native start”时找不到模块“@expo/metro-config”

我正在尝试运行命令“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)

node.js react-native

1
推荐指数
1
解决办法
2万
查看次数