小编Kom*_*omo的帖子

无法用gulp启动webpack-dev-server

当我从终端运行'webpack-dev-server'时它运行正常:

$ webpack-dev-server
http://localhost:3333/
webpack result is served from /./assets/
content is served from C:\Users\Komo\Documents\work\training
Hash: e705c984af7e83cbb685
Version: webpack 1.12.9
Time: 8556ms
    Asset    Size  Chunks             Chunk Names
bundle.js  905 kB       0  [emitted]  main
chunk    {0} bundle.js (main) 855 kB [rendered]
...
webpack: bundle is now VALID.
Run Code Online (Sandbox Code Playgroud)

我正试图用gulp开始它:

这是我的gulpfile.js:

var gulp             = require('gulp');
var gutil            = require('gulp-util');
var webpack          = require('webpack');
var WebpackDevServer = require('webpack-dev-server');
var webpackConfig    = require('./webpack.config.js');


gulp.task('webpack-dev-server', function (c) {
    var myConfig = Object.create(webpackConfig);

    myConfig.devtool = …
Run Code Online (Sandbox Code Playgroud)

gulp webpack webpack-dev-server

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

AngularJS测试:Jasmine模拟回调

我有基本的Angular JS知识,但是对Jasmine单元测试非常陌生。我的问题如下:

我需要测试一种服务方法(来自myService的方法):

myService.method = function(args)
{
    var parameter = "myParam";
    anotherService.anotherMethod(parameter, function(result)
    {
        //Stuff to test using result
        if(result == "blabla")
            testFunction("param");

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

我如何模拟anotherService.anotherMethod返回结果并测试myService.method的其余部分?我需要检查一下,例如testFunction是否已用“ param”调用(带有Expect(myFunction)toHaveBeenCalledWith(“ param”))。

坦斯克为您提供帮助

testing callback jasmine angularjs

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

从文件加载$ templateCache

我一直无法从$ templateCache加载模板.

我如何在$ templateCache中放置模板:

var app = angular.module('anglober', ['anglober.controllers', 'anglober.services', 'anglober.directives']).run(function ($templateCache, $http) {
    $http.get('anglober/js/invitation/invitationModal.tpl.html', {cache: $templateCache});
    $http.get('anglober/js/modal/ajaxModal.tpl.html', {cache: $templateCache});
    $http.get('anglober/js/ajaxLoader/ajaxLoader.tpl.html', {cache: $templateCache});
    $http.get('anglober/js/modal/modalContent.tpl.html', {cache: $templateCache});
    $http.get('anglober/js/modal/simpleModal.tpl.html', {cache: $templateCache});
    $http.get('anglober/js/mog/topMogs.tpl.html', {cache: $templateCache});
Run Code Online (Sandbox Code Playgroud)

我如何加载它们:

angular.module('anglober.directives').directive('topMogs', ['$templateCache', function ($templateCache) {
return {
    restrict : 'E',
    template: $templateCache.get('topMogs.tpl.html')
    //Tried this too
    // templateUrl: 'topMogs.tpl.html'
};
}]);
Run Code Online (Sandbox Code Playgroud)

在我的网络浏览器选项卡中,我可以看到在页面加载时加载的模板.

但是,在调用我的指令时出现以下错误:

One of template or templateUrl options is required.
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么 ?

谢谢

templates angularjs

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

MobX异步反应

嗨,我在商店中使用MobX,当计算值发生变化时,我需要进行异步反应:

class Store {
    @observable user;
    @observable something;

    @computed get firstParam () {
         return this.user && this.user.params[0];
    }

    async loadSomething () {
        reaction(
                () => this.firstParam,
                async (param) => {
                    const { data: something } = await axios.get(`url/${param}`);

                    runInAction('update state after fetching something', () => {
                        this.something = something;
                    });
                }
            );
     }

}
Run Code Online (Sandbox Code Playgroud)

我想知道使用when而不是reaction分开运行条件会有什么区别?

when(
    () => !!this.firstParam,
    async () => {
         // fetch using this.firstParam
    }
)
Run Code Online (Sandbox Code Playgroud)

javascript asynchronous store mobx

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

用电子获取用户主目录

当我require('os').homedir()从电子(4.0.1)应用程序/运行时,我得到,但是如果我直接从node运行它,则会得到主目录:

node --version
v10.14.1
 node
> require('os').homedir()
'/Users/myusername'
>
Run Code Online (Sandbox Code Playgroud)

知道为什么吗?

node.js electron

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