小编Jor*_*ald的帖子

@ types/prop-types/index没有默认导出

我正在尝试使用https://github.com/facebook/prop-types

所以我也为它安装了@ types/prop-types.https://www.npmjs.com/package/@types/prop-types

但我想这个错误.[ts]模块'"/ node_modules/@ types/prop-types/index"'没有默认导出.

我想要完成的是在withRouter文档中做了什么. https://reacttraining.com/react-router/web/api/withRouter

例如,您在JavaScript中看到PropTypes的使用:

import React from 'react'
import PropTypes from 'prop-types'
import { withRouter } from 'react-router'

// A simple component that shows the pathname of the current location
class ShowTheLocation extends React.Component {
  static propTypes = {
    match: PropTypes.object.isRequired,
    location: PropTypes.object.isRequired,
    history: PropTypes.object.isRequired
  }

  render() {
    const { match, location, history } = this.props

    return (
      <div>You are now at {location.pathname}</div>
    )
  }
}

// Create a new component that is …
Run Code Online (Sandbox Code Playgroud)

typescript reactjs react-router-v4

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

在startup.cs中访问appsetting.json值

我了解如何为appsettings.json配置服务并将它们注入控制器.但是,我需要在配置Auth时使用ConfigureServices中的值.我该怎么做?请参阅下面的示例.特别是这一行:

option.clientId = /*Need client Id from appsettings.json*/
Run Code Online (Sandbox Code Playgroud)

码:

public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();
            services.Configure<AADSettings>(Configuration.GetSection("AADSettings"));
            services.Configure<APISettings>(Configuration.GetSection("APISettings"));

            // Add Authentication services.
            services.AddAuthentication(sharedOptions =>
            {
                sharedOptions.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
                sharedOptions.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
            })
                // Configure the OWIN pipeline to use cookie auth.
                .AddCookie()
                // Configure the OWIN pipeline to use OpenID Connect auth.
                .AddOpenIdConnect(option =>
                {
                    option.clientId = /*Need client Id from appsettings.json*/

                    option.Events = new OpenIdConnectEvents
                    {
                        OnRemoteFailure = OnAuthenticationFailed,
                    };
                });
        }
Run Code Online (Sandbox Code Playgroud)

c# asp.net-core-2.0

10
推荐指数
3
解决办法
5866
查看次数

在Angular/Jasmine单元测试中绕过*ngIf

仅供参考我在github上记录了一个问题,并在bug中包含了plunkr的详细信息:https://github.com/angular/angular/issues/19292

我根本无法通过ngIf来检查值.如果我删除ngIf它工作正常.为了试图解决这个问题,我直接在beforeEach()中硬编了大使的价值.但无济于事我错过了别的东西.

在HTML中:

 <h3 class="welcome" *ngIf="ambassador"><i>{{ambassador.username}}</i></h3>
Run Code Online (Sandbox Code Playgroud)

茉莉花:

beforeEach(() => {

    TestBed.configureTestingModule({
       declarations: [ ProfileComponent, BannedComponent ],
       providers:    [ HttpClient, {provide: AmbassadorService, useClass: MockAmbassadorService } ],
       imports:      [ RouterTestingModule, FormsModule, HttpClientModule ]
    });

    fixture = TestBed.createComponent(ProfileComponent);
    component    = fixture.componentInstance;

    // AmbassadorService actually injected into the component
    ambassadorService = fixture.debugElement.injector.get(AmbassadorService);
    componentUserService = ambassadorService;
    // AmbassadorService from the root injector
    ambassadorService = TestBed.get(AmbassadorService);

    // set route params
    component.route.params = Observable.of({ username: 'jrmcdona' });
    component.ambassador = new Ambassador('41', '41a', 'jrmcdona', 4586235, …
Run Code Online (Sandbox Code Playgroud)

jasmine karma-jasmine angular

7
推荐指数
1
解决办法
5588
查看次数

使用redux-observable并订阅websocket

试图弄清楚如何获得我的史诗将会订阅websocket,然后在发出的事件从websocket滚动时调度一些动作.

我看到的示例是使用Multiplex而不是实际调用websocket上的订阅,我对改变它感到困惑.

我是这样开始的.但我相信redux observable想要一个

const socket$ = Observable.webSocket<DataEvent>(
  "ws://thewebsocketurl"
);

const bankStreamEpic = (action$, store) =>
  action$.ofType(START_BANK_STREAM).mergeMap(action => {
    console.log("in epic mergeMap");
    socket$
      .subscribe(
        e => {
          console.log("dispatch event " + e);
         distributeEvent(e);
        },
        e => {
          logger.log("AmbassadorsDataService", "Unclean socket closure");
        },
        () => {
          logger.log("AmbassadorsDataService", "Socket connection closed");
        }
      )
  });

   function distributeEvent(event: DataEvent) : void {
        //this.logger.log('AmbassadorsDataService', 'Event Received: ' + event.command + ' and id: ' + event.id);
        if(event.source === '/ambassadors/bank') {
            if( event.command === 'REMOVE') { …
Run Code Online (Sandbox Code Playgroud)

redux-observable

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

在 ngOnInit() 上发出事件

尝试在初始化期间从子组件向父组件发出事件。onchange 事件工作正常,但初始化时似乎没有任何事件发生。

该事件来自选择菜单,我们以默认选择值 2 启动选择菜单,并且我们需要父级知道该值:

子组件 HTML:

<!-- Show Season Dropdown -->
<div style="float:right">
    <select id="seasonDropDown" aria-label="Select a Season">
                  <option *ngFor="let item of seasons" [value]="item.id" [selected]="item.id === seasonId">Season {{item.id}}</option>
              </select>
</div>
Run Code Online (Sandbox Code Playgroud)

子组件:

 @Output() notify: EventEmitter<number> = new EventEmitter<number>();

  ngOnInit() {
    this.notify.emit(2);
    this.getSeasons();
  }

  public changeSeason(seasonId: number) {
    console.log('change season ' + seasonId)
    this.seasonId = seasonId;
    this.notify.emit(this.seasonId);
  }
Run Code Online (Sandbox Code Playgroud)

我们在父页面上有这个组件:

<app-seasons-dropdown (notify)="onNotify($event)"></app-seasons-dropdown>
Run Code Online (Sandbox Code Playgroud)

我们在父组件中有这个监听器:

  onNotify(event:Event):void {
    console.log('notify');
    const seasonId = (event.target as HTMLSelectElement).value;
    this.getLeaderboardBySeason(Number(seasonId));
  }
Run Code Online (Sandbox Code Playgroud)

angular

5
推荐指数
0
解决办法
5060
查看次数

在机器人启动时发送自适应卡片作为欢迎消息

我有一些代码让机器人在启动时发送消息(字符串)。

但是,不是像您在下面的代码中看到的那样发送文本。我想弄清楚在这种情况下您将如何发送自适应卡。我之前从 RootDialog 发送了一张卡片,但不是从 MessageController.cs 发送的。任何方向在这里都会很棒!

else if (message.Type == ActivityTypes.ConversationUpdate)
            {
                // Handle conversation state changes, like members being added and removed
                // Use Activity.MembersAdded and Activity.MembersRemoved and Activity.Action for info
                // Not available in all channels

                IConversationUpdateActivity iConversationUpdated = message as IConversationUpdateActivity;
                if (iConversationUpdated != null)
                {
                    ConnectorClient connector = new ConnectorClient(new System.Uri(message.ServiceUrl));

                    foreach (var member in iConversationUpdated.MembersAdded ?? System.Array.Empty<ChannelAccount>())
                    {
                        // if the bot is added, then
                        if (member.Id == iConversationUpdated.Recipient.Id)
                        {
                            var reply = ((Activity)iConversationUpdated).CreateReply($"WELCOME MESSAGE …
Run Code Online (Sandbox Code Playgroud)

c# botframework adaptive-cards

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

提供所需应用程序包的有效路径。打印:条目,“:CFBundleIdentifier”,不存在

react-native-cli: 1.0.0
react-native: 0.39.2
Run Code Online (Sandbox Code Playgroud)

我克隆了一个 React Native 项目。然后我跑了npm install然后react-native run-ios。项目失败并出现以下错误。

请不要该项目在 xcode 中运行良好。

有什么想法吗?

以下命令产生了分析器问题:

Analyze RCTLocationObserver.m
Run Code Online (Sandbox Code Playgroud)

(1 个带有分析器问题的命令)

以下构建命令失败:CompileC /Users/jordanmc/Documents/src/Safetypin%20React-Native/ios/build/Build/Intermediates/RCTLinking.build/Debug-iphonesimulator/RCTLinking.build/Objects-normal/x86_64/RCTLinkingManager。 o RCTLinkingManager.m 普通 x86_64 目标-c com.apple.compilers.llvm.clang.1_0.compiler CompileC /Users/jordanmc/Documents/src/Safetypin%20React-Native/ios/build/Build/Intermediates/RCTGeolocation.build/ Debug-iphonesimulator/RCTGeolocation.build/Objects-normal/x86_64/RCTLocationObserver.o RCTLocationObserver.m normal x86_64 Objective-c com.apple.compilers.llvm.clang.1_0.compiler CompileC /Users/jordanmc/Documents/src/Safetypin% 20React-Native/ios/build/Build/Intermediates/RCTText.build/Debug-iphonesimulator/RCTText.build/Objects-normal/x86_64/RCTTextManager.o RCTTextManager。m 普通 x86_64 目标-c com.apple.compilers.llvm.clang.1_0.compiler(3 次失败)

安装 build/Build/Products/Debug-iphonesimulator/Safetypin.app 处理命令时遇到错误 (domain=NSPOSIXErrorDomain, code=2):无法安装请求的应用程序 在提供的路径中找不到应用程序包。提供所需应用程序包的有效路径。打印:条目,“:CFBundleIdentifier”,不存在

命令失败:/usr/libexec/PlistBuddy -c 打印:CFBundleIdentifier build/Build/Products/Debug-iphonesimulator/Safetypin.app/Info.plist 打印:条目,“:CFBundleIdentifier”,不存在

react-native

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

单元测试选择菜单更改事件(未获取更新值)

试图让我的选择菜单更改事件以正确的值正确触发。它似乎正在触发,但价值没有改变。

我的组件中有以下选择菜单:

<select id="seasonDropDown" style="width:200px;height: 36px;" aria-label="Select a Season" (change)="changeSeason($event.target.value)">
        <option *ngFor="let item of seasons" [value]="item.id" [selected]="item.id === seasonId">Season {{item.id}}</option>
    </select>
Run Code Online (Sandbox Code Playgroud)

我有这个变化事件:

  public changeSeason(seasonId: number) {
    this.test = 'blah';  //for testing sake
    console.log('change season ' + seasonId)
    this.seasonId = seasonId;
    this.notify.emit(this.seasonId);
  }
Run Code Online (Sandbox Code Playgroud)

我已经尝试像下面的代码一样对其进行测试,但是commponent.seasonId从未更改其默认值。它应该在changeSeason方法中更改。我知道该方法正在触发,因为当我测试Expect(component.test).toEqual('blah')时,它将通过:

    it('should emit new season on change event', fakeAsync(() => {

        let select = fixture.debugElement.query(By.css('#seasonDropDown')).nativeElement;

        select.value = 2;
        select.selectedValue = 2;

        fixture.detectChanges();

        select.dispatchEvent(new Event('change'));
        tick();

        fixture.detectChanges();


        expect(component.seasonId).toEqual(2);
        //expect(component.test).toEqual('blah');  this will pass so I know the 
        //changeSeason event is …
Run Code Online (Sandbox Code Playgroud)

jasmine karma-jasmine angular

0
推荐指数
1
解决办法
1266
查看次数