草庐IT

redux-promise

全部标签

javascript - mocha js 断言在使用 promise 时挂起?

"usestrict";letassert=require("assert");describe("Promisetest",function(){it('shouldpass',function(done){vara={};varb={};a.key=124;b.key=567;letp=newPromise(function(resolve,reject){setTimeout(function(){resolve();},100)});p.then(functionsuccess(){console.log("success---->",a,b);assert.deepEqual

javascript - 如何在 AngularJS 中访问在 promise 中声明的变量

我是AngularJS的新手,我需要访问在Javascript中分配的变量this.reqData=this.profileService.getData();varresp1=angular.fromJson(this.reqData);this.data1;varthat=this;resp1.$promise.then(function(data){that.data1=data.resource.resource;}).catch(function(error){console.log(error);});console.log(this.data1);变量data1可以从HT

javascript - 使用 Promises 通过 Bluebird promises 库在另一个函数中调用函数

我有3个NodeJs函数。我想在这里做的是,我想调用normalizeFilePath并获取规范化路径,然后检查该文件是否存在normalizedFilePath最后这些,如果文件不存在则创建一个文件。这是使用promises(Bluebird)的第一天,我是NodeJS和JavaScript的新手。下面的代码结构越来越复杂。当然,这根本不是一个好主意。varcreateProjectFolder=function(projectName){};varcheckFileExistance=function(filePath){returnnewpromise(function(reso

javascript - React/Redux 应用程序中组件的权限检查

我正在尝试与构建React应用程序的团队合作,并试图找出创建“高阶”React组件(包装另一个组件)的最佳方法,以结合Redux数据执行身份验证商店。到目前为止,我的方法是创建一个模块,该模块由一个函数组成,该函数根据是否存在经过身份验证的用户返回一个新的React组件。exportdefaultfunctionauth(Component){classAuthenticatedextendsReact.Component{//conditionallogicrender(){constisAuth=this.props.isAuthenticated;return({isAuth?:

javascript - 在 promise 中使用 then()

我在下面的代码块中使用了promise,2firstthen()我没有返回任何值,所以我想知道第一个then()中的函数是在下一个then()中的函数之前调用的。我在Angular2中使用typescript。谢谢:DPromise.resolve().then(()=>{this.getListStatus();}).then(()=>{returnthis._laundryServiceOrderService.findAll(true,offset,this.itemsPerPage,filterQuery)}).then((response)=>{this.orders=res

javascript - React/Redux reducer 在初始化期间返回 undefined

我正在开发我的第一个React/Redux项目。一切顺利,然后我尝试创建一个新的reducer。我认为这是一个非常简单的方法,但是当我加载页面时出现错误“ReducerX在初始化期间返回未定义”。跟踪表明这是在combineReducers()中发生的。我发现了几个类似的问题,但没有解决问题。关于这个问题:WhydoIget“Reducer[...]returnedundefinedduringinitialization”despiteprovidinginitialStatetocreateStore()?问题是他们在createStore()中使用了initialState,而我

JavaScript ES6 - promise 解决和事件之间可能存在竞争条件?

是否可以在promise解析和promise等待返回之间执行用户代码?functiona(){returnnewPromise(resolve=>{setTimeout(()=>{//Betweenhere...resolve()},1000))}}asyncfunctionb(){awaita()//...andhere?}规范是否强制立即调用Promise回调?我想知道2点之间的虚拟机是否可以处理一个事件,这可能会导致副作用。 最佳答案 不,它不强制立即调用。Thespec在解决一个promise时会经历许多步骤,其中之一是:P

javascript - 为什么 Promise 没有 get() 函数?

如果您知道Promise已经被解决,为什么不能直接调用get()并接收值呢?与将then(..)与回调函数一起使用相反。所以不要这样做:promise.then(function(value){//dosomethingwithvalue});我希望能够做的更简单:varvalue=promise.get();Java为它的CompletableFuture提供了这个我看不出为什么JavaScript不能提供相同的功能。 最佳答案 Java的get方法“如有必要,等待此future完成”,即它会阻塞当前线程。我们绝对不想在只有一个“

javascript - React-Redux/Jest 不变违规 : Could not find "store"

我设置了一个简单的测试文件,几乎与create-react-app使用的文件相同:App.test.jsimportReactfrom'react';importReactDOMfrom'react-dom';import{App}from'./App';it('renderswithoutcrashing',()=>{constdiv=document.createElement('div');ReactDOM.render(,div);});当我运行yarntest我不断收到此错误消息:InvariantViolation:Couldnotfind"store"ineitherth

javascript - 将 React 本地状态与 Redux 全局状态相结合

我正在制作一个网络应用程序,用户可以在其中围绕图像中的对象绘制边界框。我如何使用React的本地状态:我在用户仍在绘图时存储矩形的属性(即在mouseMove期间mouseUp之前)。我如何使用Redux的全局存储:一次mouseUp火灾,绘图完成,并且不再对矩形进行更新。我想将这个矩形“提交”给Redux。这是处理状态管理的正确和/或规范方式吗?我还想将React和Redux状态(即现在正在绘制的矩形以及已经在Redux中“提交”的矩形)作为Prop传递给childreact组件。react-redux这可能吗?的mapStateToProps?我似乎无法在mapStateToPro