小编Och*_*wie的帖子

将Typescript与React-Redux一起使用时输入Error

我试图使用react-redux和typescript,当我尝试使用connect()和mapStateToProps注入道具时,我遇到了类型错误.

我的组件看起来像这样:

function mapStateToProps(state) {
    return {
        counter: state.counter
    };
}

function mapDispatchToProps(dispatch) {
    return {
        incr: () => {
            dispatch({type: 'INCR', by: 2});
        },
        decr: () => {
            dispatch({type: 'INCR', by: -1});
        }
    };
}




export default class Counter extends React.Component<HelloProps, any> {
    render() {
        return (
          <div>
              <p>
                  <label>Counter: </label>
                  <b>#{this.props.counter}</b>
              </p>
              <button onClick={e => this.props.incr() }>INCREMENT</button>
              <span style={{ padding: "0 5px" }}/>
              <button onClick={e => this.props.decr() }>DECREMENT</button>
        );
    }
}


export default connect(mapStateToProps, mapDispatchToProps)(Counter);
Run Code Online (Sandbox Code Playgroud)

这家商店看起来像这样

let store …
Run Code Online (Sandbox Code Playgroud)

typescript reactjs redux typescript1.8 react-redux

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

跨两个Web API项目共享OAuth令牌

我创建了一个带有OAuth令牌认证的Web API应用程序.当令牌服务器在与服务相同的应用程序上运行时,这没有问题.但是,我想将授权服务移动到自己的应用程序(VS项目)中,并将其用于我正在处理的几个Web API项目中.但是,当我将授权逻辑隔离到它自己的项目中时,原始服务不再将生成的令牌视为有效.我的问题是,一个Web API项目是否有可能为另一个Web API项目生成令牌以进行验证?这是我的授权服务和原始服务的OWIN启动代码

认证服务:

public void Configuration(IAppBuilder app)
    {
        // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=316888
        HttpConfiguration config = new HttpConfiguration();

        ConfigureOAuth(app);

        WebApiConfig.Register(config);
        app.UseWebApi(config);
        app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);
    }

    private void ConfigureOAuth(IAppBuilder app)
    {
        OAuthAuthorizationServerOptions OAuthServerOptions = new OAuthAuthorizationServerOptions()
        {
            AllowInsecureHttp = true,
            TokenEndpointPath = new PathString("/token"),
            AccessTokenExpireTimeSpan = TimeSpan.FromDays(1),
            Provider = new SimpleAuthorizationServerProvider()
        };

        // Token Generation
        app.UseOAuthAuthorizationServer(OAuthServerOptions);
        app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions());
    }
Run Code Online (Sandbox Code Playgroud)

原始服务:

public void Configuration(IAppBuilder app)
    {
        ConfigureOAuth(app);
        // For more information on how to …
Run Code Online (Sandbox Code Playgroud)

c# oauth asp.net-web-api

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

F#区分联盟中的功能

有没有办法在Discriminated Unions中使用函数?我希望做这样的事情:

Type Test<'a> = Test of 'a-> bool

我知道在Haskell中使用newtype是可能的,我想知道F#中的等价物是什么.

谢谢.

f# haskell

3
推荐指数
1
解决办法
903
查看次数

重构菜单不显示在Visual Studio 2012 RC中

在Visual Studio 2012 RC中,重构菜单没有显示给我.它没有显示在菜单栏或上下文相关帮助中.是否需要更改设置以使其显示.我在自定义选项中看到了重构菜单,但无法使其显示在菜单栏中.这是在ac#项目中.

c# visual-studio-2012

3
推荐指数
1
解决办法
3586
查看次数