小编Ste*_*fan的帖子

如何动态执行/评估包含ES6模块的JavaScript代码/需要一些依赖项?

我希望我的用户能够在我的JavaScript应用程序中使用JavaScript作为脚本语言.为此,我需要动态执行源代码.

动态执行JavaScript似乎有两个主要选项:

a)使用eval(...)方法(或var func = new Function(...);).

b)<script>向DOM 添加节点(例如,使用$('body').append(...)).

只要我不在import动态执行的源代码中使用任何语句,这两种方法都可以正常工作.如果我包含import语句,我会收到错误消息Unexpected identifier.

要执行的示例用户源代码:

import Atom from './src/core.atom.js':

window.createTreeModel = function(){
   var root = new Atom('root');
   root.createChildAtom('child');
   return root;
}
Run Code Online (Sandbox Code Playgroud)

示例应用程序代码,用于说明该动态代码的可能用法:

a)使用eval

var sourceCode =  editor.getText(); 
window.createTreeModel = undefined;
eval(sourceCode);
var model = window.createTreeModel();
treeView.setModel(model);
Run Code Online (Sandbox Code Playgroud)

b)使用DOM修改:

var sourceCode =  editor.getText(); 
window.createTreeModel = undefined;

var script = "<script >\n"+ 
            sourceCode + "\n" +             
            "</script>";

$('body').append(script); 

var model = window.createTreeModel(); …
Run Code Online (Sandbox Code Playgroud)

javascript eval dynamic-execution es6-modules

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

注册该组件时如何为vue.js组件定义CSS样式?

我可以使用注册一个自定义的vue.js组件

// register
Vue.component('my-component', {
  template: '<div class="my-class">A custom component!</div>'
})   
Run Code Online (Sandbox Code Playgroud)

另请参阅https://vuejs.org/v2/guide/components.html

如何为我的组件包括CSS类?

我希望有类似的东西

 Vue.component('my-component', {
      template: '<div class="my-class">A custom component!</div>',
      css: '#... my css stylesheet...'
    })
Run Code Online (Sandbox Code Playgroud)

但似乎没有css选择。

我知道我可以

a)在全局CSS样式表中定义所有CSS类,或

b)使用singe-file-vue-components(将需要构建工具支持* .vue文件,请参阅https://vuejs.org/v2/guide/single-file-components.html

但我宁愿

c)在注册组件时为该组件指定一个css样式表。

=>怎么做?

javascript css stylesheet vue.js vue-component

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

如何调试 java 可执行文件的类路径命令行选项(-cp)?

我想从命令行在Windows上执行 java 可执行文件(Open JDK 11.0.2),我不确定是否正确指定了类路径选项,例如

java -cp "./foo_\*/*" -version
Run Code Online (Sandbox Code Playgroud)

如何打印java 在给定类路径上可以找到的所有文件的列表?

有没有类似的东西

echo java -cp "./foo_\*/*"
Run Code Online (Sandbox Code Playgroud)

或者

java -debug -cp "./foo_\*/*" -version
Run Code Online (Sandbox Code Playgroud)

java debugging command-line

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

在Python中实现可观察集合的推荐方法?

我希望在 Python 中有一些可观察的集合/序列,让我能够监听更改事件,例如添加新项目或更新项目:

list = ObservableList(['a','b','c'])
list.addChangeListener(lambda new_value: print(new_value))
list.append('a') # => should trigger the attached change listener

data_frame = ObservableDataFrame({'x': [1,2,3], 'y':[10,20,30]})
data_frame.addChangeListener(update_dependent_table_cells) # => allows to only update dependent cells instead of a whole table
Run Code Online (Sandbox Code Playgroud)

答:我发现以下项目提供了可观察集合的实现,并且看起来很有前途:

https://github.com/dimsf/Python-observable-collections

它做了我想要的:

from observablelist import ObservableList

def listHandler(event):
    if event.action == 'itemsUpdated':
        print event.action + ', old items: ' + str(event.oldItems) + ' new items: ' + str(event.newItems) + ' at index: ' + str(event.index)
    elif event.action == 'itemsAdded' or event.action == …
Run Code Online (Sandbox Code Playgroud)

python collections sequence observable observer-pattern

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

如何使用 SSH 密钥将 GitLab 存储库镜像到 GitHub?

GitLab 有镜像功能:

https://docs.gitlab.com/ee/user/project/repository/mirror/

并且GitHub不支持简单的密码认证。我试着跟随

https://meesvandongen.nl/posts/mirror-gitlab-github

使用目标网址

ssh://git@github.com:stefaneidelloth/mirror_demo.git
Run Code Online (Sandbox Code Playgroud)

SSH public key作为身份验证方法。

但是,我收到错误

Remote mirrors url is blocked: URI is invalid 
Run Code Online (Sandbox Code Playgroud)

来自亚搏体育实验室。

如果我指定目标网址

https://github.com/stefaneidelloth/mirror_demo.git
Run Code Online (Sandbox Code Playgroud)

我无法选择SSH public key身份验证方法。

=> 将 GitLab 项目镜像到 GitHub 项目(没有 GitLab PREMIUM 版本)的正确设置是什么?

编辑

第二个:需要替换为/.

GitHub 推荐:

在此输入图像描述

添加ssh://前缀是不够的。

错误的:ssh://git@github.com:stefaneidelloth/mirror_demo.git

github.com后仍需更换:

正确的:ssh://git@github.com/stefaneidelloth/mirror_demo.git

然后GitLab生成连接的SSH密钥,需要将其复制到GitHub项目设置(而不是用户设置),请参阅https://meesvandongen.nl/posts/mirror-gitlab-github

现在我收到下一个错误:

13:get remote references: create git ls-remote: exit status 128, stderr: "ssh connect to host github.com port 22: Connection timed out\r\nfatal: Could …
Run Code Online (Sandbox Code Playgroud)

git github gitlab

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

JavaFx:如何为节点的给定样式类获取相应的样式表?

我能够检索 JavaFx 节点“节点”的样式类

List<String> styleClasses = node.getStyleClass();
Run Code Online (Sandbox Code Playgroud)

例如,这给了我样式类“chart-plot-background”。

如何从节点检索相应的当前活动样式表条目?

Caspian.css 文件包含条目

.chart-plot-background {
-fx-background-color: #f5f5f5;
}
Run Code Online (Sandbox Code Playgroud)

我希望能够至少使用以下代码片段从节点中检索此信息:

一种。

Style style = node.getStyle();
//is empty
Run Code Online (Sandbox Code Playgroud)

B.

Parent parent = (Parent) node;
List<String> styleSheets = parent.getStyleSheets();
//... loop through the list and search for the entry...
//however, the list is empty
Run Code Online (Sandbox Code Playgroud)

C。

List<CssMetaData<? extends Styleable, ?>> cssMetaDataList = node.getCssMetaData();
//... loop through the list and search for the entry...
//however, the property "-fx-background-color" is null
Run Code Online (Sandbox Code Playgroud)

相关老文章:

解析节点的 CSS 属性

指向错误票

http://bugs.openjdk.java.net/browse/JDK-8091202

动机 …

css javafx stylesheet

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

2017年Resharper的Jasmine单元测试支持状态:是否支持调试模式和AMD模块?

我目前使用Chutzpah来运行和调试包含AMD/require.js模块的Jasmine Unit测试.我想转到2017年Resharper的试运行员.但是,Resharper似乎并不完全支持Jasmine单元测试?

A.茉莉花测试示例:

/// <reference path="../../bower_components/requirejs/require.js" />
/// <reference path="../../bower_components/jasmine-core/lib/jasmine-core/jasmine.js" />

describe('dummy example test', function() {
  it("should return bar", function () {
    expect(true).toEqual(true);
  });
});
Run Code Online (Sandbox Code Playgroud)

可以使用Resharper运行Test,但禁用Debugging选项: 在此输入图像描述

B.模块定义的示例测试:

/// <reference path="../../bower_components/requirejs/require.js" />
/// <reference path="../../bower_components/jasmine-core/lib/jasmine-core/jasmine.js" />

define(['Squire'], function(squire) {

  describe('dummy example test', function() {
    it("should return bar", function() {
      expect(true).toEqual(true);
      alert('has been executed');
    });
  });

});
Run Code Online (Sandbox Code Playgroud)

如果我从Resharper开始,测试永远不会结束,并且不会调用it方法.

Resharper 2016是否真的不支持Jasmine单元测试的调试以及AMD模块的单元测试?或者我是否需要以某种方式调整我的Resharper设置以使Debugging和AMD/requirejs模块工作?

这是我目前的设置: 在此输入图像描述

(由于Chutzpah和Resharper 10都使用过时的Jasmine版本,我也愿意接受与VisualStudio很好集成的进一步建议.)

编辑:Resharper 2016似乎支持Jasmine版本> 2.0.

相关(不是最新的?)文章:

编辑

这些问题最初发布于Resharper 10.它们仍然适用于2016年的Resharper.

resharper unit-testing amd requirejs jasmine

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

如何在 Visual Studio 中执行自定义文件特定命令/任务?

我希望能够为 VisualStudio 解决方案定义自定义命令/任务/宏。然后我想对在Solution Explorer.

有几种可能来执行对我来说没问题的命令:

a) 右键单击​​中的文件Solution Explorer并从上下文菜单中选择命令(我最喜欢的)

b) 在Solution Explorer. 然后单击工具栏上的按钮。然后该命令会以某种方式从Solution Explorer.

c) 在Solution Explorer. 然后从Task Runner Explorer. 执行的任务会以某种方式从“解决方案资源管理器”中检索所选文件

我尝试使用 VisualStudio 扩展VsCommandBuddy。但是,它不支持特定于文件的命令,请参阅

https://github.com/PaulHuizer/VsCommandBuddy/issues/21

我还试图用一个GruntGulp可从启动任务Task Runner Explorer。但是,我不知道如何传递/访问当前Solution Explorer.

https://blogs.msdn.microsoft.com/webdev/2016/01/06/task-runners-in-visual-studio-2015/

=> 是否有一个 VisualStudio 扩展可以轻松地为文件定义自定义命令?

=> 如何在脚本文件(例如 Gulp、Grunt、Webpack)中传递/访问在 SolutionExplorer 中选择的文件?

=> 您会推荐其他任何舒适的工作流程吗?

可以编写我自己的 VisualStudio 扩展。但我想其他人已经知道了解决方案。

task visual-studio gruntjs add-custom-command gulp

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

如何导入html中<script type ="module">标签中定义的es6模块?

我可以在我的html文件me.html中定义一个模块:

<script type="module" id="DEFAULT_MODULE">   
           import Atom from './atom.js';       
           console.log("definition of getAtom")
           export default function getAtom(){
            return new Atom('atom');
           }
           console.log("exported getAtom")
</script>
Run Code Online (Sandbox Code Playgroud)

另见

=>是否可以将"匿名"模块导入同一个html文件中的另一个模块脚本?或者某些"代码隐藏" - 也是由me.html文件加载的JavaScript文件?出口似乎有效; 至少它不会抛出任何错误.

为了导入getAtom我试过的方法,例如:

<script type="module">
    import getAtom from '.'; //this line does not work
    console.log("usage of getAtom")
    var atom = getAtom();             
</script>
Run Code Online (Sandbox Code Playgroud)

我希望有一些语法

 import getAtom;
 import getAtom from '.';
 import getAtom from window;
 import getAtom from './me.html';
 import getAtom from '.DEFAULT_MODULE';
Run Code Online (Sandbox Code Playgroud)

但是,这些线都不起作用.

=>如果可能的话,引用"匿名"模块的正确语法是什么?

我使用Chrome版本63.0.3239.108.

相关问题:

如何动态执行/评估包含ES6模块的JavaScript代码/需要一些依赖项?

html javascript es6-modules

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

如何包含我的自定义 jupyter 笔记本扩展使用的额外 javascript 库?

我想编写一个 Jupyter Notebook 扩展,如下所述:https ://towardsdatascience.com/how-to-write-a-jupyter-notebook-extension-a63f9578a38c

Jupyter Notebook 似乎带有一组默认的 JavaScript 库(例如 jquery、下划线等)。我在下面找到了那些库

python-3.7.1.amd64\Lib\site-packages\notebook\static\components
Run Code Online (Sandbox Code Playgroud)

我的笔记本扩展需要更多的库,例如 gold-layout.js 和 d3.js。

=> 是否可以定义额外的必需 JavaScript 库,在安装我的扩展时将其安装到上述组件文件夹中?

作为一种解决方法,我可以将库复制到我的自定义扩展文件夹的子文件夹“bower_components”,例如

python-3.7.1.amd64\Lib\site-packages\jupyter_contrib_nbextensions\nbextensions\my_extension_folder\bower_components
Run Code Online (Sandbox Code Playgroud)

然后我会尝试调整 require 配置以能够加载这些库。但是,这似乎很棘手,并且可能会由于某些库的双重安装而导致其他扩展出现问题?

=> 满足我的依赖项的推荐方法是什么?

编辑

如果我使用以相对根“nbextensions”开头的详细路径,则无需更改 require 配置:

require([
    'nbextensions/my_extension_folder/bower_components/golden-layout/dist/goldenlayout.min',
    'nbextensions/my_extension_folder/bower_components/d3/d3.min'   
], function(
    GoldenLayout,
    d3  
) {             
  alert('foo');    
});
Run Code Online (Sandbox Code Playgroud)

我仍然想知道这是否是正确的方法。

javascript jupyter-notebook jupyter-contrib-nbextensions

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