0608零散问题整理

1. redux store

createStore
Creates a Redux store that holds the complete state tree of your app. There should only be a single store in your app.
The only way to change its state is by dispatching actions.
You may also subscribe to the changes to its state to update the UI.

Enhance store: middleware / enhancers
Most apps extend the functionality of their Redux store by adding middleware or store enhancers (note: middleware is common, enhancers are less common). Middleware adds extra functionality to the Redux dispatch function; enhancers add extra functionality to the Redux store.

Enhance store: middleware / enhancers 补充
applyMiddleware lets you inject functionality into dispatch. As it turns out, you do this by writing a function, that returns a function, that returns a function. No, I’m afraid I’m not joking.
Only the inner-most function runs on each dispatch.

Using Thunk Middleware for Async Actions:

2. “Element Type is invalid” exception

Element Type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

import MyButton from '../index';
// 改为:
import { MyButton } from '../index';

详细解释:

This is a default import:

// B.js
import A from './A'

It only works if A has the default export:

// A.js
export default 42

This is a named import called A:

import { A } from './A'

It only works if A contains a named export called A:

export const A = 42

3. combine gradle spring backend with react redux UI

  1. need include frontend in settings.gradle
  2. need in service build.gradle
processResources {
	from("../UI/target/distro/") {into "static" include "index-webpack-*.min.js"}
	from("../UI/target/distro/css") {into "static/css" include "main-*.min.css"}
	from("../UI/target/distro/fonts") {into "static/fonts"}
	from("../UI/target/distro/images") {into "static/images"}
	from("../UI/target/distro/") {into "template" include "index.html"}
}
  1. need write controller in backend: using @Controller, @GetMapping…
  2. need @Configuration file: SpringWebMVCConfig. (Example)
  3. build project together with frontend, if extra env is needed for frontend, build project in terminal after config the env for frontend(using command in terminal).
// step 1:
// initial env for frontend
// step 2:
gradlew.bat build

4. 剩余的一些零散知识点

  1. How to test React with Jest & Enzyme

import fetchMock from 'fetch-mock'

window.alert = jest.fn();

describe("My Component", () => {

	afterEach(() => {
		window.alert.mockClear();
		fetchMock.restore();
	});
	
	it('create MY_ROUTINE_SUCCESS when fetching is done', () => {
		fetchMock.getOnce(url,
			{actionPayloadData: ['response Something']}
		);
		....
	});
});
  1. what is the difference between jest.fn() and an empty function
    jest.fn() has more methods to use, .mock, .mock.calls…

  2. arrow function can omit return:

const func = () => "result";

// equivalent to:
const func = () => {
	return "result"
};
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值