0809-1004 setTimeout, cellRenderer, onClick called on render, read list RestTemplate, fetchMock 500

    科技2022-08-04  123

    1. List - Using the spread operator in React

    以前笔记好像写过…但是是关于map-{}的,这次是关于list-[]的。

    var colors = ['red', 'green', 'blue']; var refColors = [...colors, 'yellow']; //colors => ['red', 'green', 'blue'] //refColors => ['red', 'green', 'blue', 'yellow']

    2. setTimeout ReactJS with arrow function es6

    3. Radio-buttons instead of checkboxes?

    最后用的还是ag-grid自带的checkbox,方形的,改了这里:

    rowSelection: 'single'

    4. Chrome: CSS Style is applied only when you go to Google Developer tools

    turns out it’s because… 95% width set in SCSS file only applied when the page is too narrow… (this part I am not sure why) When the page is normal size, I forget to set the width for the outside component that contains it…

    5. preventDefault() Event Method

    https://www.w3schools.com/JSREF/event_preventdefault.asp#:~:text=The preventDefault() method cancels,link from following the URL

    When to use PreventDefault( ) vs Return false?

    6. Cell Renderer

    anyway, cellRenderer’s props.data is the row you clicked… props.value is based on the workflow of valueFormatter and so on, like the figure in above link (or more specific, the link below: ) Cell Rendering Flow

    7. Bootstrap alert overlapping button

    still a bit wired, so I put alert component beyond button component finally…

    8. Why is my onClick being called on render? - React.js

    这个用的是React.component,写在render里,本来用的onClick={this.function(param1)},但是每次param1改变这个function就被call,搞死我了,后来改成 onClick={() =>this.function(param1)} 就可以了

    9. alert block doesn’t start a new line

    https://github.com/FasterXML/jackson-databind/issues/585

    private static final ObjectWriter objectWriter = new ObjectMapper().writer(new DefaultPrettyPrinter() .withObjectIndenter(new DefaultIndenter().withLinefeed("\n")));

    最后用了最朴素的方法,但是感觉也不是都换行了…

    message.replace(/,/g, ',\n')

    10. toString error, cannot resolve method toString()

    That’s because tipTotal is a primitive type double.

    Use one of the following methods,

    "" +tipTotal; Double.toString(tipTotal); String.valueOf(tipTotal); new Double(tipTotal).toString(); String.format("%f", tipTotal) ;

    11. How to compare objects by multiple fields

    本来想用stream类似的,但没找到类似的fancy的方法,有人说用自定义comparator… 最后我用的for(i=0)循环,傻傻的

    12. Get list of JSON objects with Spring RestTemplate

    ResponseEntity<List<Rate>> rateResponse = restTemplate.exchange("https://bitpay.com/api/rates", HttpMethod.GET, null, new ParameterizedTypeReference<List<Rate>>() { }); List<Rate> rates = rateResponse.getBody();

    13. spyOn

    spy on wrapper.instance() method not called when using shallow()

    How To Use spyOn on a function inside of functional component

    14. 2 different kind of errors (thrown at different places…backend/frontend)

    fetchMock.postOnce(url, { status: 500, body: { errorMessage: "some known error from backend" }, {method: 'POST'} ); fetchMock.postOnce(url, { throws: "unknow error" } );

    15. Actions must be plain objects. Use custom middleware for async actions

    Actually, move mockStore.dispatch = jest.fn() before Provider solved this question

    const mockStore = createStore(combinedReducer, currentState); mockStore.dispatch = jest.fn(); const wrapper = Enzyme.mount( <Provider store={mockStore}> <YourComponent {...props} /> </Provider> );
    Processed: 0.017, SQL: 8