小编Rol*_*llo的帖子

如何在使用babel和webpack时生成源图?

我是webpack的新手,我需要设置一下来生成源图.我正在webpack serve从命令行运行,它成功编译.但我真的需要源图.这是我的webpack.config.js.

var webpack = require('webpack');

module.exports = {

  output: {
    filename: 'main.js',
    publicPath: '/assets/'
  },

  cache: true,
  debug: true,
  devtool: true,
  entry: [
      'webpack/hot/only-dev-server',
      './src/components/main.js'
  ],

  stats: {
    colors: true,
    reasons: true
  },

  resolve: {
    extensions: ['', '.js', '.jsx'],
    alias: {
      'styles': __dirname + '/src/styles',
      'mixins': __dirname + '/src/mixins',
      'components': __dirname + '/src/components/',
      'stores': __dirname + '/src/stores/',
      'actions': __dirname + '/src/actions/'
    }
  },
  module: {
    preLoaders: [{
      test: /\.(js|jsx)$/,
      exclude: /node_modules/,
      loader: 'jsxhint'
    }],
    loaders: …
Run Code Online (Sandbox Code Playgroud)

javascript build-process source-maps webpack babeljs

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

为什么Django Rest Framework不鼓励模型级验证?

Django Rest Framework序列化程序不会调用Model.clean何时验证模型序列化程序.给出的解释是,这可以从Django Rest Framework 3.0发行说明中获得"更清晰的关注点分离" :

ModelSerializer验证和ModelForm之间的差异.

此更改还意味着我们不再.full_clean()在模型实例上使用该方法,而是在序列化程序上显式执行所有验证.这样可以实现更清晰的分离,并确保ModelSerializer类上没有自动验证行为,这些行为也无法在常规Serializer类上轻松复制.

但是,什么样的关注是Django的REST框架的尝试分开的作者?


我的猜测是,他们说模型实例不应该关注它自身的有效性.如果是这样的话,我不明白为什么.

python django serialization django-models django-rest-framework

30
推荐指数
1
解决办法
4222
查看次数

ElasticSearch更新不是立竿见影的,你如何等待ElasticSearch完成更新它的索引?

我正在尝试提高针对ElasticSearch进行测试的套件的性能.

测试需要很长时间,因为Elasticsearch在更新后不会立即更新它的索引.例如,以下代码运行时不会引发断言错误.

from elasticsearch import Elasticsearch
elasticsearch = Elasticsearch('es.test')

# Asumming that this is a clean and empty elasticsearch instance
elasticsearch.update(
     index='blog',
     doc_type=,'blog'
     id=1,
     body={
        ....
    }
)

results = elasticsearch.search()
assert not results
# results are not populated
Run Code Online (Sandbox Code Playgroud)

目前解决这个问题的解决方案是将time.sleep调用放入代码中,以便给ElasticSearch一些时间来更新它的索引.

from time import sleep
from elasticsearch import Elasticsearch
elasticsearch = Elasticsearch('es.test')

# Asumming that this is a clean and empty elasticsearch instance
elasticsearch.update(
     index='blog',
     doc_type=,'blog'
     id=1,
     body={
        ....
    }
)

# Don't want to use sleep functions
sleep(1) …
Run Code Online (Sandbox Code Playgroud)

python synchronization polling wait elasticsearch

15
推荐指数
3
解决办法
6149
查看次数

UITextView自动高度

如何将UITextView扩展或缩小到其中文本的大小,然后使UIScrollview展开或缩小以适应UITextView

iphone xcode objective-c ipad ios

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

使用Jest CLI时如何让Promise工作?

我正在尝试使用Jest CLI测试一个promise,这个代码在浏览器中运行时应该执行.但是我想开始为它编写测试.

class ListCollection {
  constructor() { 
    this.items = new Array();
  }

  addItem(string) {
    const addItemPromise = new Promise(
      function (resolve, reject) {
        // set up async getting like a XMLHttpRequest
        setTimeout( () => {
          this.items.push(string);
          resolve(string);
        }.bind(this), 2000);
      }.bind(this)
    );
    return addItemPromise;
  }
}
Run Code Online (Sandbox Code Playgroud)

目前我正试图让这个非常基本的测试工作.我正在pit根据链接到jasmine-pit文档进行测试.

jest.dontMock('../collections');

import Collection       from '../collections';

describe("Collection", () => {
    let collection;

    beforeEach(() => {
        collection = new Collection();
    });

    describe("Adding an item", () => {
        pit('Spec 1', function …
Run Code Online (Sandbox Code Playgroud)

javascript node.js jasmine reactjs jestjs

6
推荐指数
1
解决办法
4162
查看次数

在Jest-CLI中测试时如何使用superagent?

我需要从远程URL中获取测试中的一些真实数据.我Superagent并没有被嘲笑.我已经做了,包括那个node_modules/superagent/unmockedModulePathPatterns.

这是我试图测试的文件,.end()从不调用该函数.

这是我的测试,它因超时错误而失败.

jest.dontMock("../Stocks.js");
jest.dontMock("superagent");

describe("Stock Actions", () => {
  var makeRequest = require('../Stocks')

  pit("doesn't crash", function () {
    var promise = makeRequest("Hello World")

    promise.then(function (str) {
      expect(str).toBe("yay");
    });

    return promise;
  });
});
Run Code Online (Sandbox Code Playgroud)

这是它试图测试的模块:

import Reflux     from 'reflux';
import request    from 'superagent';

console.log("request-superagent", request)

const makeRequest = Reflux.createAction({ asyncResult: true });

const Store = Reflux.createStore({
  init() {
    this.listenTo(makeRequest, 'onMakeRequest');
  },

  onMakeRequest(url) {

    request('GET', 'http://api.example.com/list/')
        .end(function (err, res) {
          console.log("res.text", res.text);
          if (!res.ok) {
            makeRequest.failed("aw"); …
Run Code Online (Sandbox Code Playgroud)

testing ajax jasmine superagent jestjs

6
推荐指数
0
解决办法
857
查看次数

不兼容的指针类型Xcode

很抱歉对社区造成了这样的负担,但我真的被困在这里了.

语义问题:使用类型NewCustomCell *表达式初始化的不兼容指针类型UITableViewCell *

static NSString *cellID = @"customCell";

NewCustomCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
Run Code Online (Sandbox Code Playgroud)

xcode objective-c ios xcode4

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

SetText已弃用

嗨,我正在研究Xcode和Obj-C,我收到了这个警告:

弃用:'setText:'已弃用

我想知道新方法是什么

这是我的代码:

[cell setText:[NSString stringWithFormat:@"I am cell %d", indexPath.row]];
Run Code Online (Sandbox Code Playgroud)

xcode objective-c ios xcode4

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

Swift:如何在显示子视图之前获取其大小?

视图(a)包含一个子视图(b),该子视图包含一个文本标签。

文本标签的文本设置在viewDidLoad视图(a)中。标签中的文本量会更改子视图(b)的大小。

我仅在视图(a)中获得子视图(b)的正确大小viewDidAppear,而在中没有viewDidLayoutSubviews

如何在显示视图(a)的视图控制器中获取子视图(b)的大小?

更新:使用自动布局

uiviewcontroller uiview autolayout swift

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