小编Ale*_*ada的帖子

Angular2:它慢吗?

刚刚看一下角度团队推出的最后一个角度版本.Angular2已经出局,他们已经发布了他们的新网页http://angular.io.

在那里,他们有一个5分钟的快速入门项目,可以快速显示新语法以及您必须使用什么来执行新的角度应用程序.

我刚刚完成了所有步骤以使其正常工作,但加载时间为4.93秒.

我只是想知道,角2是慢吗?或者我可能会错过一些步骤.

这是我的代码

// app.es6

import {Component, Template, bootstrap} from 'angular2/angular2';

// Annotation section
@Component({
  selector: 'my-app'
})
@Template({
  inline: '<h1>Hello {{ name }}</h1>'
})
// Component controller
class MyAppComponent {
   constructor() {
     this.name = 'Alex!';
   }
}

bootstrap(MyAppComponent);
Run Code Online (Sandbox Code Playgroud)

和index.html

<!-- index.html -->
<html>
  <head>
    <title>Angular 2 Quickstart</title>
    <script src="dist/es6-shim.js"></script>
  </head>
  <body>

    <!-- The app component created in app.js -->
    <my-app></my-app>

    <script>
      // Rewrite the paths to load the files
      System.paths = {
        'angular2/*':'angular2/*.js', // Angular …
Run Code Online (Sandbox Code Playgroud)

javascript google-chrome angular

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

karma + jasmine + webpack:module不是函数

由于这个错误,我无法实例化控制器,它说:

  • 模块不是一个功能

应该做什么模块是angular.mock的别名,但我的问题是:

它是否可以从webpack重写模块而不是模块?(module.exports)

这是我的karma.config.js档案:

/*global __dirname*/
// Karma configuration

var path = require('path');
var webpackConfig = require('./webpack.config');

module.exports = function(config) {
config.set({

      // base path that will be used to resolve all patterns (eg. files, exclude)
      basePath: __dirname,

      // frameworks to use
      // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
      frameworks: ['jasmine'],

      // list of files / patterns to load in the browser
      files: [
          'src/Bundle/Resources/assets/base/base.js',
          'src/**/*.spec.js'
      ],

      // list of files to exclude
      exclude: [],

      // preprocess matching files before …
Run Code Online (Sandbox Code Playgroud)

angularjs karma-jasmine webpack

12
推荐指数
1
解决办法
5826
查看次数

使用带样式的组件“ as”道具和打字稿

我目前正在构建一个模式库,其中已Button使用React和构建了一个组件styled-components。基于该Button组件,我希望所有Links组件看起来完全相同,并接收完全相同的道具。为此,我使用as来自中的prop styled-components,它使我可以将已构建的元素用作另一个标签或组件。

按钮组件

import * as React from 'react'
import { ButtonBorderAnimation } from './ButtonAnimation'
import { ButtonProps, ButtonVariant } from './Button.types'
import { ButtonBase, LeftIcon, RightIcon } from './Button.styled'

function Button({
  variant = ButtonVariant.Filled,
  children,
  leftIcon = null,
  rightIcon = null,
  ...props
}: ButtonProps): JSX.Element {
  return (
    <ButtonBase variant={variant} {...props}>
      {variant !== ButtonVariant.Ghost ? (
        <ButtonBorderAnimation {...props} />
      ) : null}
      {leftIcon ? <LeftIcon>{leftIcon}</LeftIcon> : …
Run Code Online (Sandbox Code Playgroud)

javascript typescript reactjs styled-components react-router-dom

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

未捕获的ReferenceError:未定义jasmineRequire

我的测试有问题,运行它们时出现此错误:

09 09 2015 14:55:27.174:INFO [Chrome 45.0.2454 (Mac OS X 10.10.1)]: Connected on socket 9aXAoBK8a1zKw9IVAAAA with id 22794373
Chrome 45.0.2454 (Mac OS X 10.10.1) ERROR
Uncaught ReferenceError: jasmineRequire is not defined
at /Users/agarcia/Projects/affiliate-suite/node_modules/karma/jasmine/lib/boot.js:15
Run Code Online (Sandbox Code Playgroud)

这是我的karma.conf.js文件:

/*global __dirname*/
// Karma configuration

var path = require('path');

module.exports = function(config) {
  config.set({

        // base path that will be used to resolve all patterns (eg. files, exclude)
        basePath: __dirname,

        // frameworks to use
        // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
        frameworks: ['jasmine'],

        // list of files / patterns …
Run Code Online (Sandbox Code Playgroud)

javascript jasmine angularjs karma-jasmine

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

返回react-router-dom时浏览器历史记录不起作用

我们正在开发一个用 dotnet 编写的带有 Razor 视图(纯后端堆栈)的项目。我们计划将每个视图移至React用于react-router-dom处理客户端和服务器中的路由。

我们的想法是一页一页地移动,而不是大爆炸,因为该项目已经在生产中。

客户端路由器

import { Router } from 'react-router-dom'
import { createBrowserHistory, History } from 'history'

const history: History = createBrowserHistory({ basename: baseUrl })

<Router history={history}>
  <Switch>
      <Route path="/example" component={Example} />
      ...
   </Switch>
</Router>
Run Code Online (Sandbox Code Playgroud)

服务器路由器

import { StaticRouter } from 'react-router-dom'

<StaticRouter
 basename={basename}
 context={routerContext}
 location={params.location.path}
>
   <Switch>
      <Route path="/example" component={Example} />
      ...
   </Switch>
</StaticRouter>
Run Code Online (Sandbox Code Playgroud)

问题

/当我从(在 React 路由器中)导航到/example(在 .net 路由器中)然后尝试返回到 时/example,看起来没有转换到 React 路由器,并且浏览器历史记录保持在/

javascript reactjs react-router react-router-dom

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

没想到服务器 HTML 在 &lt;main&gt; 中包含一个 &lt;div&gt;

我在一个使用以下项目的项目中工作:

  • 反应/反应-dom@16.9.0
  • @loadable/组件
  • 样式组件
  • 反应路由器dom

该应用程序呈现服务器端和客户端。

我正在使用@loadable/component这种方式动态代码拆分。

路由器.tsx

import * as React from 'react'
import loadable from '@loadable/component'
import { Route, Switch } from 'react-router-dom'

const NotFound = loadable(() =>
  import('../components/NotFound/NotFound' /* webpackChunkName: "notfound" */)
)

const routes = (
  <Switch>
    <Route component={NotFound} />
  </Switch>
)

export default routes
Run Code Online (Sandbox Code Playgroud)

加载页面时,此错误出现在控制台上,页面似乎闪烁了一秒钟。

react-dom.development.js:546 Warning: Did not expect server HTML to contain a <div> in <main>.
Run Code Online (Sandbox Code Playgroud)

当我检查双方(服务器/客户端)的输出时,它们是相同的

当我@loadable/component像下面那样删除时,它可以工作并且错误消失了。

路由器无负载.tsx

import * as React …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs server-side-rendering react-router-dom loadable-component

4
推荐指数
1
解决办法
4878
查看次数

日期之间的 Hasura graphql 查询

在我的 hasura.io 数据库中,我有一个booking表,我在其中存储具有以下属性的预订:

  • id(自动递增)
  • 来自(时间戳)
  • 到(时间戳)
  • 描述(文本)

现在,从 UI 中,当用户进行预订时,我想检查之前是否有任何涉及这些日期范围的预订。

例如。用户想要在以下日期进行预订:

{
  "from": "2020-03-31T14:00:00+00:00",
  "to": "2020-03-31T17:00:00+00:00"
}
Run Code Online (Sandbox Code Playgroud)

但在同一天有一个预订:

{
  "from": "2020-03-31T15:00:00+00:00",
  "to": "2020-04-01T17:00:00+00:00"
}
Run Code Online (Sandbox Code Playgroud)

请注意,此预订不是在用户尝试预订的日期范围内进行的。因此,以下查询将不返回任何内容。

query CheckBooking($from: timestamptz!, $to: timestamptz!) {
  booking(where: {_and: [{from: {_lte: $from}}, {to: {_gte: $to}}]}) {
    id
    from
    to
  }
}
Run Code Online (Sandbox Code Playgroud)

以上是我尝试过但没有成功的方法。任何人都可以帮助找出检查范围内或用户新预订内是否有任何预订的正确查询是什么

gql graphql react-apollo hasura

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