我试图理解a Route和a 之间的区别Resource.我理解的方式Resource有助于将Route对象的子路径设置为另一个Route对象.但是当我想到路径的默认名称映射时,我还不清楚.
我正在寻找这样的东西
function someFunc() {
callAjaxfunc(); //may have multiple ajax calls in this function
someWait(); // some code which waits until async calls complete
console.log('Pass2');
}
function callAjaxfunc() {
//All ajax calls called here
console.log('Pass1');
}
Run Code Online (Sandbox Code Playgroud)
我试过了什么?
1 Jquery.when()
尝试使用它..工作正常.但不是我想要的方式.$.when将等待,但旁边的代码$.when()运行没有等待.里面的代码do callback只在ajax调用之后运行
2. setTimeOut()带有全局标志
我非常有信心这会奏效.我试过跟随.
GlobalFlag = false;
function someFunc()
callAjaxfunc(); //may have multiple ajax calls in this function
setTimeOut(waitFunc, 100); // some which waits until async calls complete
console.log('Pass2');
}
function callAjaxfunc() {
//All ajax …Run Code Online (Sandbox Code Playgroud) 我正在尝试以开玩笑的方式为我的Web组件项目编写测试.我已经使用了带有es2015预设的babel.我在加载js文件时遇到问题.我已经跟踪了一段代码,其中document对象有一个currentScript对象.但在测试环境中它是null.所以我在想同样的嘲笑.但是jest.fn()并没有真正的帮助.我该如何处理这个问题?
一段代码,其中开玩笑失败.
var currentScriptElement = document._currentScript || document.currentScript;
var importDoc = currentScriptElement.ownerDocument;
Run Code Online (Sandbox Code Playgroud)
我写的测试用例. component.test.js
import * as Component from './sample-component.js';
describe('component test', function() {
it('check instance', function() {
console.log(Component);
expect(Component).toBeDefined();
});
});
Run Code Online (Sandbox Code Playgroud)
以下是jest抛出的错误
Test suite failed to run
TypeError: Cannot read property 'ownerDocument' of null
at src/components/sample-component/sample-component.js:4:39
Run Code Online (Sandbox Code Playgroud)
更新: 根据AndreasKöberle的建议,我添加了一些全球变量,并试图嘲笑如下
__DEV__.document.currentScript = document._currentScript = {
ownerDocument: ''
};
__DEV__.window = {
document: __DEV__.document
}
__DEV__.document.registerElement = jest.fn();
import * as Component from './arc-sample-component.js'; …Run Code Online (Sandbox Code Playgroud) 我们可以像这样为ListView创建数据源
var ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
var dataSource = ds.cloneWithRows(['row 1', 'row 2']), };
Run Code Online (Sandbox Code Playgroud)
但是,如果我想添加项目或从数据源中删除项目,我该怎么做?我是否需要始终使用更新的数组调用cloneWithRows?
无论如何我们可以避免在少数情况下运行可观察代码?
我怎么试过? 我发现要避免的唯一方法是在视图中添加新属性作为标志,如果在运行可观察方法代码之前进行检查.
这是我提供基本观察者功能HTML的基本jsfiddle链接
<script type="text/x-handlebars" data-template-name="application">
{{view MyApp.MyContainerView name="Santa Claus"}}
</script>
<script type="text/x-handlebars" data-template-name="foo">
{{view.testProp}}
</script>
Run Code Online (Sandbox Code Playgroud)
JS
MyApp = Ember.Application.create({
autoinit: false
});
MyApp.router = Ember.Router.create({
root: Ember.Route.extend({
index: Ember.Route.extend({
route: '/'
})
})
});
MyApp.ApplicationController = Ember.Controller.extend({});
MyApp.MyContainerView = Em.ContainerView.extend({
childViews: ['foo'],
foo: Em.View.extend({
testProp: 100,
testPropObservable: function(){
console.log("Prop Observed");
}.observes('testProp'),
init: function() {
this._super();
this.set('testProp', 200);//i want to avoid obeserver here
},
templateName: 'foo'
})
});
MyApp.initialize(MyApp.router);
Run Code Online (Sandbox Code Playgroud) 我有自己的私人npm注册表http://something.我安装了纱线并尝试运行以下命令.
yarn
Run Code Online (Sandbox Code Playgroud)
但它给出了以下错误.
Trace:
Error: unable to get local issuer certificate
at Error (native)
at TLSSocket.<anonymous> (_tls_wrap.js:1017:38)
at emitNone (events.js:67:13)
at TLSSocket.emit (events.js:166:7)
at TLSSocket._init.ssl.onclienthello.ssl.oncertcb.TLSSocket._finishInit (_tls_wrap.js:582:8)
at TLSWrap.ssl.onclienthello.ssl.oncertcb.ssl.onnewsession.ssl.onhandshakedone (_tls_wrap.js:424:38)
Run Code Online (Sandbox Code Playgroud)
我发现了几个github问题和解决方案.
https://github.com/yarnpkg/yarn/issues/841 https://github.com/yarnpkg/yarn/commit/b0611a6ee5220b0b1e955b271b6140640158f96c(0.16.0可用)
看起来我必须strict-ssl在yarn配置中设置为false.我无法确切地知道我该怎么做.我尝试在package.json中以下列方式提供选项但是没有用.
1)
{
config: {
"strict-ssl": false
}
}
Run Code Online (Sandbox Code Playgroud)
2)
{
"strict-ssl": false
}
Run Code Online (Sandbox Code Playgroud)
但我仍然得到同样的错误.我哪里做错了?
我在我的应用程序中使用网络组件。在 Web 组件中,我需要插入一个 React 组件。Web 组件有 Shadow DOM。当我尝试使用以下方式渲染反应组件时,出现错误。
comp = React.createElement(ReactElem, {
config: config,
onRender: handleRender
});
ReactDOM.render(comp , self.shadowRoot.querySelector('#app1'));
Run Code Online (Sandbox Code Playgroud)
错误
target container is not a dom element
Run Code Online (Sandbox Code Playgroud)
我尝试使用contentWeb 组件 API,但随后它呈现在组件顶部而不是内部。有什么线索可以让 React 组件在 Shadow DOM 中渲染吗?
我在路径中有一个反应组件
src/components/test
import React from 'react';
import ReactDom from 'react-dom';
class TestComp extends React.Component {}
export default TestComp;
Run Code Online (Sandbox Code Playgroud)
我在路径中公开index.js中的组件
src/index.js
import TestComp from './components/test';
export {
TestComp
};
Run Code Online (Sandbox Code Playgroud)
我main在package.json中添加了"main": "src/index.js"
我已经发布了test-comp上述应用程序的npm包,并在另一个应用程序中使用了它.
main.js
import {TestComp} from 'test-comp';
Run Code Online (Sandbox Code Playgroud)
我在此应用程序中使用grunt-browserify并设置了以下选项.
options: {
"transform": [
[
"babelify",
{
"presets": [
"es2015",
"react",
"stage-0"
]
}
]
],
browserifyOptions: {
debug: true,
extensions: ['.js', '.jsx'],
entries: ['main.js']
}
}
Run Code Online (Sandbox Code Playgroud)
当我grunt browserify遇到跟随错误.
>> import TestComp from './components/test';
>> ^ …Run Code Online (Sandbox Code Playgroud) 我有一个需要 afunction或 的道具Component。所以我想通过检查 prop 的类型来区分它是组件还是函数。我目前正在使用以下一种。当代码被混淆时,这可能在产品中不起作用。想知道更好的解决方案吗?
let isSvelteComponent = component => {
return (
typeof component !== "undefined" &&
component.__proto__.name === "SvelteComponentDev"
);
};
Run Code Online (Sandbox Code Playgroud) sendAction()在Ember.Component默认情况下气泡到控制器,这是预期的.但我有2,3个动作,我宁愿发送到使用该组件的相应视图.在模板中,我们设置了要使用的操作target=view.我们可以这样做吗?
更新:目前作为一种解决方法,我将视图对象发送到组件,该组件从那里调用view.send()发送操作.但我觉得这不正确.
javascript ×4
ember.js ×3
reactjs ×2
babel-jest ×1
browserify ×1
ember-router ×1
es6-modules ×1
jestjs ×1
jquery ×1
jsdom ×1
node-modules ×1
react-native ×1
shadow-dom ×1
svelte ×1
svelte-3 ×1
yarnpkg ×1