Best JavaScript code snippet using storybook-root
iterationArrayValueChange_ArrayFromAttribute_PassThroughValueTest.js
Source:iterationArrayValueChange_ArrayFromAttribute_PassThroughValueTest.js
1/*2 * Copyright (C) 2013 salesforce.com, inc.3 *4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 *8 * http://www.apache.org/licenses/LICENSE-2.09 *10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */16({17 //two tests for clear and replace the whole array. this one replace attribute, the one below replace directly iteration items.18 //notice the difference in re-rendering count, as replacing attribute won't trigger re-render, it just destroy & replace the whole thing19 testClearAndReplaceWholeArrayInAttribute: {20 test: [function(cmp) {21 cmp.set("v.listdata",[]);22 }, function(cmp) {23 var expected = [];24 var iterCmpEle = cmp.find("iterationOnArrayAttributePassthrough").getElements();25 $A.test.assertEquals( expected.length, iterCmpEle.length, "number of element in iteration component is not expected after clear v.listdata." );26 27 cmp.set("v.listdata",[1,2,3,4,5]);28 }, function(cmp) {29 var expected = [30 {render_count: 1, rerender_count: 0, unrender_count:0, passthrough_string: "1"},31 {render_count: 1, rerender_count: 0, unrender_count:0, passthrough_string: "2"},32 {render_count: 1, rerender_count: 0, unrender_count:0, passthrough_string: "3"},33 {render_count: 1, rerender_count: 0, unrender_count:0, passthrough_string: "4"},34 {render_count: 1, rerender_count: 0, unrender_count:0, passthrough_string: "5"}];35 var iterCmpEle = cmp.find("iterationOnArrayAttributePassthrough").getElements();36 $A.test.assertEquals( expected.length, iterCmpEle.length, "number of element in iteration component is not expected after replace v.listdata." );37 this.assertIterationCmpElements(expected, iterCmpEle);38 }39 ]40 },41 42 testClearAndReplaceWholeArrayInIteration: {43 test: [function(cmp) {44 var iter = cmp.find("iterationOnArrayAttributePassthrough");45 iter.set("v.items",[]);46 }, function(cmp) {47 var expected = [];48 var iterCmpEle = cmp.find("iterationOnArrayAttributePassthrough").getElements();49 $A.test.assertEquals( expected.length, iterCmpEle.length, "number of element in iteration component is not expected after clear v.items in iteration." );50 51 var iter = cmp.find("iterationOnArrayAttributePassthrough");52 iter.set("v.items",["1","2","3","4","5"]);53 }, function(cmp) {54 var iterCmpEle = cmp.find("iterationOnArrayAttributePassthrough").getElements();55 var expected = [56 {render_count: 1, rerender_count: 0, unrender_count:0, passthrough_string: "1"},57 {render_count: 1, rerender_count: 0, unrender_count:0, passthrough_string: "2"},58 {render_count: 1, rerender_count: 0, unrender_count:0, passthrough_string: "3"},59 {render_count: 1, rerender_count: 0, unrender_count:0, passthrough_string: "4"},60 {render_count: 1, rerender_count: 0, unrender_count:0, passthrough_string: "5"}];61 $A.test.assertEquals( expected.length, iterCmpEle.length, "number of element in iteration component is not expected after replace v.items in iteration." );62 this.assertIterationCmpElements(expected, iterCmpEle);63 }64 ]65 },66 67 //notice that changing start and end doesn't trigger rerender.68 testChangeStartAndEnd: {69 attributes: {start:0, end:5},70 test: [function(cmp) {71 cmp.set("v.start", 1);72 }, function(cmp) {73 var iterCmpEle = cmp.find("iterationOnArrayAttributePassthrough").getElements();74 var expected = [75 {render_count: 1, rerender_count: 0, unrender_count:0, passthrough_string: "1"},76 {render_count: 1, rerender_count: 0, unrender_count:0, passthrough_string: "2"},77 {render_count: 1, rerender_count: 0, unrender_count:0, passthrough_string: "3"},78 {render_count: 1, rerender_count: 0, unrender_count:0, passthrough_string: "4"}];79 this.assertIterationCmpElements(expected, iterCmpEle);80 }, function(cmp) {81 cmp.set("v.end", 4);82 }, function(cmp) {83 var iterCmpEle = cmp.find("iterationOnArrayAttributePassthrough").getElements();84 var expected = [85 {render_count: 1, rerender_count: 0, unrender_count:0, passthrough_string: "1"},86 {render_count: 1, rerender_count: 0, unrender_count:0, passthrough_string: "2"},87 {render_count: 1, rerender_count: 0, unrender_count:0, passthrough_string: "3"}];88 this.assertIterationCmpElements(expected, iterCmpEle);89 }90 ]91 },92 93 //check elements in iteration component 94 //if we change the value in attribute directly, rerender doesn't happen to that iteration item, hence the count is 095 assertIterationCmpElements: function(expected, cmpElements) {96 $A.test.assertEquals( expected.length, cmpElements.length, "number of element in iteration component is not expected." );97 for(var i = 0; i< expected.length; i++) {98 var eleText = $A.test.getText(cmpElements[i]);99 var exp = expected[i];100 $A.test.assertTrue(eleText.indexOf("Passthrough String: "+exp.passthrough_string) > -1, "unexpected Passthrough String");101 $A.test.assertTrue(eleText.indexOf("render count: "+exp.render_count) > -1, "unexpected render count");102 $A.test.assertTrue(eleText.indexOf("rerender count: "+exp.rerender_count) > -1, "unexpected rerender count");103 $A.test.assertTrue(eleText.indexOf("unrender count: "+exp.unrender_count) > -1, "unexpected unrerender count");104 }105 },106 107 testSetItemsInIteration:{108 attributes:{ indexToChange:1 , newValueToChange:999 },109 test: [function(cmp){110 var index = parseInt(cmp.get("v.indexToChange"), 10);111 var newValue = cmp.get("v.newValueToChange");112 var iter = cmp.find("iterationOnArrayAttributePassthrough");113 var data = iter.get("v.items");114 data[index] = newValue; 115 iter.set("v.items", data);116 }, function(cmp) {117 var iterCmpEle = cmp.find("iterationOnArrayAttributePassthrough").getElements();118 var expected = 119 [{render_count: 1, rerender_count: 1, unrender_count:0, passthrough_string: "0"},120 {render_count: 1, rerender_count: 0, unrender_count:0, passthrough_string: "999"},121 {render_count: 1, rerender_count: 1, unrender_count:0, passthrough_string: "2"},122 {render_count: 1, rerender_count: 1, unrender_count:0, passthrough_string: "3"},123 {render_count: 1, rerender_count: 1, unrender_count:0, passthrough_string: "4"}];124 125 this.assertIterationCmpElements(expected, iterCmpEle);126 127 var v_listdata = cmp.get("v.listdata");128 for(var i = 0; i < v_listdata.length; i++) {129 $A.test.assertEquals( expected[i].passthrough_string, v_listdata[i].toString(), "unexpected map data at index#"+i );130 }131 }]132 },133 134 135 testSetItemsInAttribute: {136 attributes:{ indexToChange:1 , newValueToChange:999 },137 test: [function(cmp){138 var index = parseInt(cmp.get("v.indexToChange"), 10);139 var newValue = cmp.get("v.newValueToChange");140 var data = cmp.get("v.listdata");141 data[index] = newValue; 142 cmp.set("v.listdata", data);143 }, function(cmp) {144 var iterCmpEle = cmp.find("iterationOnArrayAttributePassthrough").getElements();145 var expected = 146 [{render_count: 1, rerender_count: 1, unrender_count:0, passthrough_string: "0"},147 {render_count: 1, rerender_count: 0, unrender_count:0, passthrough_string: "999"},148 {render_count: 1, rerender_count: 1, unrender_count:0, passthrough_string: "2"},149 {render_count: 1, rerender_count: 1, unrender_count:0, passthrough_string: "3"},150 {render_count: 1, rerender_count: 1, unrender_count:0, passthrough_string: "4"}];151 this.assertIterationCmpElements(expected, iterCmpEle);152 }]153 },154 155 testInsertItemsInIteration:{156 attributes:{ indexToInsert:0 , newValueToInsert:999 },157 test: [function(cmp){158 var index = parseInt(cmp.get("v.indexToInsert"), 10);159 var newValue = cmp.get("v.newValueToInsert");160 var iter = cmp.find("iterationOnArrayAttributePassthrough");161 var data = iter.get("v.items");162 data.splice ( index, 0, newValue); 163 iter.set("v.items", data);164 }, function(cmp) {165 var iterCmpEle = cmp.find("iterationOnArrayAttributePassthrough").getElements();166 var expected = 167 [{render_count: 1, rerender_count: 0, unrender_count:0, passthrough_string: "999"},168 {render_count: 1, rerender_count: 1, unrender_count:0, passthrough_string: "0"},169 {render_count: 1, rerender_count: 1, unrender_count:0, passthrough_string: "1"},170 {render_count: 1, rerender_count: 1, unrender_count:0, passthrough_string: "2"},171 {render_count: 1, rerender_count: 1, unrender_count:0, passthrough_string: "3"},172 {render_count: 1, rerender_count: 1, unrender_count:0, passthrough_string: "4"}];173 this.assertIterationCmpElements(expected, iterCmpEle);174 175 var v_listdata = cmp.get("v.listdata");176 for(var i = 0; i < v_listdata.length; i++) {177 $A.test.assertEquals( expected[i].passthrough_string, v_listdata[i].toString(), "unexpected map data at index#"+i );178 }179 }]180 },181 182 testInsertItemsInAttribute: {183 attributes:{ indexToChange:0 , newValueToInsert:999 },184 test: [function(cmp){185 var index = parseInt(cmp.get("v.indexToInsert"), 10);186 var newValue = cmp.get("v.newValueToInsert");187 var data = cmp.get("v.listdata");188 data.splice ( index, 0, newValue); 189 cmp.set("v.listdata", data);190 }, function(cmp) {191 var iterCmpEle = cmp.find("iterationOnArrayAttributePassthrough").getElements();192 var expected = 193 [{render_count: 1, rerender_count: 0, unrender_count:0, passthrough_string: "999"},194 {render_count: 1, rerender_count: 1, unrender_count:0, passthrough_string: "0"},195 {render_count: 1, rerender_count: 1, unrender_count:0, passthrough_string: "1"},196 {render_count: 1, rerender_count: 1, unrender_count:0, passthrough_string: "2"},197 {render_count: 1, rerender_count: 1, unrender_count:0, passthrough_string: "3"},198 {render_count: 1, rerender_count: 1, unrender_count:0, passthrough_string: "4"}];199 this.assertIterationCmpElements(expected, iterCmpEle);200 }]201 },202 203 testDeleteItemsInIteration:{204 attributes:{ indexToDelete:0 },205 test: [function(cmp){206 var index = parseInt(cmp.get("v.indexToInsert"), 10);207 var iter = cmp.find("iterationOnArrayAttributePassthrough");208 var data = iter.get("v.items");209 data.splice ( index, 1); 210 iter.set("v.items", data);211 }, function(cmp) {212 var index = parseInt(cmp.get("v.indexToInsert"), 10);213 var iterCmpEle = cmp.find("iterationOnArrayAttributePassthrough").getElements();214 var expected = 215 [{render_count: 1, rerender_count: 1, unrender_count:0, passthrough_string: "1"},216 {render_count: 1, rerender_count: 1, unrender_count:0, passthrough_string: "2"},217 {render_count: 1, rerender_count: 1, unrender_count:0, passthrough_string: "3"},218 {render_count: 1, rerender_count: 1, unrender_count:0, passthrough_string: "4"}];219 this.assertIterationCmpElements(expected, iterCmpEle);220 221 222 var v_listdata = cmp.get("v.listdata");223 for(var i = 0; i < v_listdata.length; i++) {224 $A.test.assertEquals( expected[i].passthrough_string, v_listdata[i].toString(), "unexpected map data at index#"+i );225 }226 }]227 },228 229 testDeleteItemsInAttribute: {230 attributes:{ indexToDelete:0 },231 test: [function(cmp){232 var index = parseInt(cmp.get("v.indexToInsert"), 10);233 var data = cmp.get("v.listdata");234 data.splice ( index, 1); 235 cmp.set("v.listdata", data);236 }, function(cmp) {237 var index = parseInt(cmp.get("v.indexToInsert"), 10);238 var iterCmpEle = cmp.find("iterationOnArrayAttributePassthrough").getElements();239 var expected = 240 [{render_count: 1, rerender_count: 1, unrender_count:0, passthrough_string: "1"},241 {render_count: 1, rerender_count: 1, unrender_count:0, passthrough_string: "2"},242 {render_count: 1, rerender_count: 1, unrender_count:0, passthrough_string: "3"},243 {render_count: 1, rerender_count: 1, unrender_count:0, passthrough_string: "4"}];244 this.assertIterationCmpElements(expected, iterCmpEle);245 }]246 }247 248 ...
av-grid-rerender-check.js
Source:av-grid-rerender-check.js
1const range = (left, right) => Array.from({length: right - left + 1}, (_, i) => left + i);2const markStickyLeftDirty = (rerender, input) => range(0, input.stickyLeft - 1)3 .forEach(i => rerender.columns[i] = true);4const markStickyRightDirty = (rerender, input) => range(input.columnCount - input.stickyRight, input.columnCount - 1)5 .forEach(i => rerender.columns[i] = true);6const markStickyTopDirty = (rerender, input) => range(0, input.stickyTop - 1)7 .forEach(i => rerender.rows[i] = true);8const markStickyBottomDirty = (rerender, input) => range(1, input.stickyBottom)9 .forEach(i => rerender.rows[input.rowCount - i] = true);10const markStickyTopDiffDirty = (rerender, old, input) => 11 range(Math.min(old.input.stickyTop, input.stickyTop) + 1, Math.max(old.input.stickyTop, input.stickyTop))12 .forEach(i => rerender.rows[i - 1] = true);13const markStickyBottomDiffDirty = (rerender, old, input) => range(1, Math.max(old.input.stickyBottom, input.stickyBottom))14 .forEach(i => rerender.rows[input.rowCount - i] = true);15const markStickyLeftDiffDirty = (rerender, old, input) =>16 range(Math.min(old.input.stickyLeft, input.stickyLeft) + 1, Math.max(old.input.stickyLeft, input.stickyLeft))17 .forEach(i => rerender.columns[i - 1] = true);18const markStickyRightDiffDirty = (rerender, old, input) => range(1, Math.max(old.input.stickyRight, input.stickyRight))19 .forEach(i => rerender.columns[input.columnCount - i] = true);20function markVisibleColumnDirty(rerender, old, input){21 range(old.rendered.left, old.rendered.right).forEach(i => rerender.columns[i] = true);22 markStickyLeftDirty(rerender, input);23 markStickyRightDirty(rerender, input);24}25function markVisibleRowDirty(rerender, old, input){26 for (let i = old.rendered.top; i <= old.rendered.bottom; i++){27 rerender.rows[i] = true;28 }29 markStickyTopDirty(rerender, input);30 markStickyBottomDirty(rerender, input);31}32function markDirtyWidth(rerender, old, columnLength){33 let res = false;34 let dirtyIndex = old.columnLength.findIndex((oldLength, idx) => oldLength !== columnLength[idx]);35 if (dirtyIndex < 0){36 return false;37 }38 if (dirtyIndex < old.rendered.right){39 range(Math.max(dirtyIndex, old.rendered.left), old.rendered.right).forEach(i => rerender.columns[i] = true);40 res = true;41 }42 if (dirtyIndex < old.input.stickyLeft){43 markStickyLeftDirty(rerender, old.input);44 res = true;45 }46 if (old.input.stickyRight && dirtyIndex <= old.input.columnCount - old.input.stickyRight){47 markStickyRightDirty(rerender, old.input);48 res = true;49 }50 51 return res;52}53function markDirtyHeight(rerender, old, rowLength){54 let res = false;55 let dirtyIndex = old.rowLength.findIndex((oldLength, idx) => oldLength !== rowLength[idx]);56 if (dirtyIndex < 0){57 return false;58 }59 if (dirtyIndex < old.rendered.bottom){60 range(Math.max(dirtyIndex, old.rendered.top), old.rendered.bottom).forEach(i => rerender.rows[i] = true);61 res = true;62 }63 if (dirtyIndex < old.input.stickyTop){64 markStickyTopDirty(rerender, old.input);65 res = true;66 }67 if (old.input.stickyBottom && dirtyIndex <= old.input.rowCount - old.input.stickyBottom){68 markStickyBottomDirty(rerender, old.input);69 res = true;70 }71 72 return res;73}74export function prepareRerender(rerender, old, input, columnLength, rowLength){75 let res;76 let empty;77 if (!rerender){78 res = {79 rows: {},80 columns: {},81 cells: {}82 }83 empty = true;84 } else {85 const rows = (rerender.rows || []).filter(r => r >= old.rendered.top && r <= old.rendered.bottom);86 const columns = (rerender.columns || []).filter(c => c >= old.rendered.left && c <= old.rendered.right);87 const cells = (rerender.cells || [])88 .filter(({row, col}) => row >= old.rendered.top && row <= old.rendered.bottom &&89 col >= old.rendered.left && col <= old.rendered.right90 );91 empty = !(rows.length || columns.length || cells.length);92 res = {93 rows: rows.reduce((acc, r) => {acc[r] = true; return acc}, {}),94 columns: columns.reduce((acc, c) => {acc[c] = true; return acc}, {}),95 cells: cells.reduce((acum, {row, col}) => {96 acum[`${row}_${col}`] = true;97 return acum;98 }, {}),99 }100 }101 if (old.input.stickyTop !== input.stickyTop){102 markStickyTopDiffDirty(res, old, input);103 markStickyLeftDirty(res, input);104 markStickyRightDirty(res, input);105 empty = false;106 }107 if (old.input.stickyBottom !== input.stickyBottom){108 markStickyBottomDiffDirty(res, old, input);109 empty = false;110 }111 if (old.input.stickyLeft !== input.stickyLeft){112 markStickyLeftDiffDirty(res, old, input);113 empty = false;114 }115 if (old.input.stickyRight !== input.stickyRight){116 markStickyRightDiffDirty(res, old, input);117 empty = false;118 }119 if (old.input.rowCount !== input.rowCount){120 markStickyBottomDirty(res, old.input);121 markStickyBottomDirty(res, input);122 empty = false;123 }124 if (old.input.columnCount !== input.columnCount){125 markStickyRightDirty(res, old.input);126 markStickyRightDirty(res, input);127 empty = false;128 }129 if ( (typeof old.columnLength === 'number') ^ (typeof columnLength === 'number') ){130 markVisibleColumnDirty(res, old, input);131 empty = false;132 } else {133 if (typeof columnLength === 'number'){134 if (old.columnLength !== columnLength){135 markVisibleColumnDirty(res, old, input);136 empty = false;137 }138 } else {139 if (markDirtyWidth(res, old, columnLength)){140 empty = false;141 }142 } 143 }144 if ( (typeof old.rowLength === 'number') ^ (typeof rowLength === 'number') ){145 markVisibleRowDirty(res, old, input);146 empty = false;147 } else {148 if (typeof rowLength === 'number'){149 if (old.rowLength !== rowLength){150 markVisibleRowDirty(res, old, input);151 empty = false;152 }153 } else {154 if (markDirtyHeight(res, old, rowLength)){155 empty = false;156 }157 } 158 }159 160 if (empty){161 return null;162 }163 164 return res;...
script.js
Source:script.js
...113 s.settings.color = Object.keys(colors).map((i) => {114 return colors[i];115 });116 }117 rerender();118 };119 const gui = new dat.GUI({ load: options });120 const part = gui.addFolder('Particles');121 part.open();122 part.add(s.settings, 'count', 1, 500, 1).onFinishChange(rerender);123 part.add(s.settings, 'shape', shapes).onFinishChange(rerender);124 part.add(s.settings, 'style', styles).onFinishChange(rerender);125 const image = part.addFolder('Image');126 // image.add(s.settings, "imageUrl").onFinishChange(rerender);127 part.add(s.settings, 'minSize', 1, 50, 1).onFinishChange(rerender);128 part.add(s.settings, 'maxSize', 1, 50, 1).onFinishChange(rerender);129 const anim = gui.addFolder('Animation');130 anim.add(s.settings, 'direction', 0, 360, 1).onFinishChange(rerender);131 anim.add(s.settings, 'speed', 0, 100, 0.1).onFinishChange(rerender);...
App.js
Source:App.js
1import React, {useState} from 'react';2import PersonalDetails from './components/personal_details';3import EducationalQual from './components/educational_quals';4import WorkExperience from './components/work_experience';5import SubmitCV from "./components/submit_cv";6import './css/personalStyles.css';7const App = () => {8 const [editMode, setEditMode] = useState(true);9 const [name, setName] = useState('');10 const [email, setEmail] = useState('');11 const [phone, setPhone] = useState('');12 const [city, setCity] = useState('');13 const [country, setCountry] = useState('');14 const [education, setEducation] = useState([]);15 const [work, setWork] = useState([]);16 const [rerender,setRerender] = useState(false)17 18 const handleSubmit = (e) => {19 let education_copy = education;20 for(let i=0; i < education_copy.length;i++) {21 education_copy[i].editing = false;22 }23 setEducation(education_copy)24 let work_copy = work;25 for(let i=0; i < work_copy.length;i++) {26 work_copy[i].editing = false;27 }28 setWork(work_copy)29 let new_state=(editMode)?false:true;30 setEditMode(new_state)31 }32 const handleInput = (target,value) => {33 let setOfVariables = {34 "name": setName,35 "email": setEmail,36 "phone": setPhone,37 "city": setCity,38 "country": setCountry39 }40 setOfVariables[target](value);41 }42 const handleEducationInput = (values) => {43 setEducation([...education,values])44 }45 const handleEducationDelete = (index) => {46 let education_copy = education;47 education_copy[index].deleted = true;48 setEducation(education_copy)49 let rerender_copy = rerender;50 rerender_copy = (rerender)? false : true;51 setRerender(rerender_copy)52 }53 const HandleEducationEdit = (index) => {54 let education_copy = education;55 education_copy[index].editing = (education_copy[index].editing)? false : true;56 setEducation(education_copy)57 let rerender_copy = rerender;58 rerender_copy = (rerender)? false : true;59 setRerender(rerender_copy)60 }61 const handleEducationUpdate = (index,values) => {62 let education_copy = education;63 education_copy[index].degree = values.degree;64 education_copy[index].uni = values.uni;65 education_copy[index].desc = values.desc;66 education_copy[index].start = values.start;67 education_copy[index].end = values.end;68 education_copy[index].ongoing = values.ongoing;69 education_copy[index].editing = false;70 setEducation(education_copy)71 let rerender_copy = rerender;72 rerender_copy = (rerender)? false : true;73 setRerender(rerender_copy)74 }75 const handleWorkInput = (values) => {76 setWork([...work,values])77 }78 const handleWorkDelete = (index) => {79 let work_copy = work;80 work_copy[index].deleted = true;81 setWork(work_copy)82 let rerender_copy = rerender;83 rerender_copy = (rerender)? false : true;84 setRerender(rerender_copy)85 }86 const handleWorkEdit = (index) => {87 let work_copy = work;88 work_copy[index].editing = (work_copy[index].editing)? false : true;89 setWork(work_copy)90 let rerender_copy = rerender;91 rerender_copy = (rerender)? false : true;92 setRerender(rerender_copy)93 }94 const handleWorkUpdate = (index,values) => {95 let work_copy = work;96 work_copy[index].designation = values.designation;97 work_copy[index].company = values.company;98 work_copy[index].rnr = values.rnr;99 work_copy[index].from = values.from;100 work_copy[index].to = values.to;101 work_copy[index].ongoing = values.ongoing;102 work_copy[index].editing = false;103 setWork(work_copy)104 let rerender_copy = rerender;105 rerender_copy = (rerender)? false : true;106 setRerender(rerender_copy)107 }108 return (109 <div className="App" className="cv_section">110 <PersonalDetails 111 onType={handleInput}112 editMode={editMode}113 name={name}114 email={email}115 phone={phone}116 city={city}117 country={country}118 />119 <EducationalQual120 editMode={editMode}121 education={education}122 onAdd={handleEducationInput}123 onDelete={handleEducationDelete}124 onEdit={HandleEducationEdit}125 onUpdate={handleEducationUpdate}126 />127 <WorkExperience128 editMode={editMode}129 work={work}130 onAdd={handleWorkInput}131 onDelete={handleWorkDelete}132 onEdit={handleWorkEdit}133 onUpdate={handleWorkUpdate}134 />135 <SubmitCV136 onSubmit={handleSubmit}137 editMode={editMode}138 />139 </div>140 );141}...
rerender.js
Source:rerender.js
1'use strict';2angular.module('showcase.rerender', ['datatables', 'ngResource'])3.controller('RerenderDefaultRendererCtrl', RerenderDefaultRendererCtrl)4.controller('RerenderAjaxRendererCtrl', RerenderAjaxRendererCtrl)5.controller('RerenderPromiseRendererCtrl', RerenderPromiseRendererCtrl)6.controller('RerenderNGRendererCtrl', RerenderNGRendererCtrl);7function RerenderDefaultRendererCtrl(DTOptionsBuilder, DTColumnDefBuilder) {8 var vm = this;9 vm.dtOptions = DTOptionsBuilder.newOptions();10 vm.dtColumnDefs = [11 DTColumnDefBuilder.newColumnDef(0),12 DTColumnDefBuilder.newColumnDef(1).notVisible(),13 DTColumnDefBuilder.newColumnDef(2).notSortable()14 ];15 vm.dtInstance = {};16}17function RerenderAjaxRendererCtrl(DTOptionsBuilder, DTColumnBuilder) {18 var vm = this;19 vm.dtOptions = DTOptionsBuilder.fromSource('data.json');20 vm.dtColumns = [21 DTColumnBuilder.newColumn('id').withTitle('ID'),22 DTColumnBuilder.newColumn('firstName').withTitle('First name').notVisible(),23 DTColumnBuilder.newColumn('lastName').withTitle('Last name').notSortable()24 ];25 vm.dtInstance = {};26}27function RerenderPromiseRendererCtrl($resource, DTOptionsBuilder, DTColumnBuilder) {28 var vm = this;29 vm.dtOptions = DTOptionsBuilder.fromFnPromise(function() {30 return $resource('data.json').query().$promise;31 });32 vm.dtColumns = [33 DTColumnBuilder.newColumn('id').withTitle('ID'),34 DTColumnBuilder.newColumn('firstName').withTitle('First name').notVisible(),35 DTColumnBuilder.newColumn('lastName').withTitle('Last name').notSortable()36 ];37 vm.dtInstance = {};38}39function RerenderNGRendererCtrl($resource, DTOptionsBuilder, DTColumnDefBuilder) {40 var vm = this;41 vm.persons = [];42 vm.dtOptions = DTOptionsBuilder.newOptions();43 vm.dtColumnDefs = [44 DTColumnDefBuilder.newColumnDef(0),45 DTColumnDefBuilder.newColumnDef(1).notVisible(),46 DTColumnDefBuilder.newColumnDef(2).notSortable()47 ];48 vm.dtInstance = {};49 $resource('data.json').query().$promise.then(function(persons) {50 vm.persons = persons;51 });...
topic_closing_view.js
Source:topic_closing_view.js
1/**2 This view is used for rendering the notification that a topic will3 automatically close.4 @class TopicClosingView5 @extends Discourse.View6 @namespace Discourse7 @module Discourse8**/9Discourse.TopicClosingView = Discourse.View.extend({10 elementId: 'topic-closing-info',11 delayedRerender: null,12 shouldRerender: Discourse.View.renderIfChanged('topic.details.auto_close_at'),13 render: function(buffer) {14 if (!this.present('topic.details.auto_close_at')) return;15 var autoCloseAt = moment(this.get('topic.details.auto_close_at'));16 if (autoCloseAt < new Date()) return;17 var duration = moment.duration(autoCloseAt - moment());18 var timeLeftString, rerenderDelay, minutesLeft = duration.asMinutes();19 if (minutesLeft > 1410) {20 timeLeftString = I18n.t('in_n_days', {count: Math.round(duration.asDays())});21 if( minutesLeft > 2160 ) {22 rerenderDelay = 12 * 60 * 60000;23 } else {24 rerenderDelay = 60 * 60000;25 }26 } else if (minutesLeft > 90) {27 timeLeftString = I18n.t('in_n_hours', {count: Math.round(duration.asHours())});28 rerenderDelay = 30 * 60000;29 } else if (minutesLeft > 2) {30 timeLeftString = I18n.t('in_n_minutes', {count: Math.round(duration.asMinutes())});31 rerenderDelay = 60000;32 } else {33 timeLeftString = I18n.t('in_n_seconds', {count: Math.round(duration.asSeconds())});34 rerenderDelay = 1000;35 }36 buffer.push('<h3><i class="fa fa-clock-o"></i> ');37 buffer.push( I18n.t('topic.auto_close_notice', {timeLeft: timeLeftString}) );38 buffer.push('</h3>');39 // TODO Sam: concerned this can cause a heavy rerender loop40 this.set('delayedRerender', Em.run.later(this, this.rerender, rerenderDelay));41 },42 willDestroyElement: function() {43 if( this.delayedRerender ) {44 Em.run.cancel(this.get('delayedRerender'));45 }46 }...
topic-closing.js.es6
Source:topic-closing.js.es6
1import StringBuffer from 'discourse/mixins/string-buffer';2export default Ember.Component.extend(StringBuffer, {3 elementId: 'topic-closing-info',4 delayedRerender: null,5 rerenderTriggers: ['topic.closed',6 'topic.details.auto_close_at',7 'topic.details.auto_close_based_on_last_post',8 'topic.details.auto_close_hours'],9 renderString(buffer) {10 if (!!Ember.isEmpty(this.get('topic.details.auto_close_at'))) return;11 if (this.get("topic.closed")) return;12 var autoCloseAt = moment(this.get('topic.details.auto_close_at'));13 if (autoCloseAt < new Date()) return;14 var duration = moment.duration(autoCloseAt - moment());15 var minutesLeft = duration.asMinutes();16 var timeLeftString = duration.humanize(true);17 var rerenderDelay = 1000;18 if (minutesLeft > 2160) {19 rerenderDelay = 12 * 60 * 60000;20 } else if (minutesLeft > 1410) {21 rerenderDelay = 60 * 60000;22 } else if (minutesLeft > 90) {23 rerenderDelay = 30 * 60000;24 } else if (minutesLeft > 2) {25 rerenderDelay = 60000;26 }27 var basedOnLastPost = this.get("topic.details.auto_close_based_on_last_post");28 var key = basedOnLastPost ? 'topic.auto_close_notice_based_on_last_post' : 'topic.auto_close_notice';29 var autoCloseHours = this.get("topic.details.auto_close_hours") || 0;30 buffer.push('<h3><i class="fa fa-clock-o"></i> ');31 buffer.push( I18n.t(key, { timeLeft: timeLeftString, duration: moment.duration(autoCloseHours, "hours").humanize() }) );32 buffer.push('</h3>');33 // TODO Sam: concerned this can cause a heavy rerender loop34 this.set('delayedRerender', Em.run.later(this, this.rerender, rerenderDelay));35 },36 willDestroyElement() {37 if( this.delayedRerender ) {38 Em.run.cancel(this.get('delayedRerender'));39 }40 }...
useHasNotEqual.test.js
Source:useHasNotEqual.test.js
1import { renderHook } from '@testing-library/react-hooks'2import useHasNotEqual from '../useHasNotEqual'3const _getHas = result => result.current;4const _rerender = (result, rerender, value, expectedResult ) => {5 rerender({ value })6 expect(_getHas(result)).toBe(expectedResult)7};8describe('useHasNotEqual', ()=>{9 test('should return false for initial render and for same value for next rerender', ()=>{10 const is = true11 , {12 result,13 rerender14 } = renderHook(({value}) => useHasNotEqual(value), {15 initialProps: { value: is }16 });17 expect(_getHas(result)).toBe(false)18 const _testRerender = _rerender.bind(null, result, rerender)19 // for bool...
Using AI Code Generation
1import { render } from 'react-dom';2import { getStorybookUI, configure } from '@storybook/react-native';3import { loadStories } from './storyLoader';4import { getStorybookRoot } from '@storybook/react-native-server';5import { AppRegistry } from 'react-native';6configure(() => {7 loadStories();8}, module);9const StorybookUIRoot = getStorybookRoot({10});11AppRegistry.registerComponent('storybook', () => StorybookUIRoot);12import { configure } from '@storybook/react-native';13import { loadStories } from './storyLoader';14configure(() => {15 loadStories();16}, module);17import { configure } from '@storybook/react-native';18configure(() => {19 require('../src/components/atoms/Button/Button.stories');20 require('../src/components/atoms/Text/Text.stories');21 require('../src/components/molecules/Checkbox/Checkbox.stories');22 require('../src/components/molecules/Icon/Icon.stories');23 require('../src/components/molecules/IconWithText/IconWithText.stories');24 require('../src/components/molecules/Modal/Modal.stories');25 require('../src/components/molecules/ModalWithInput/ModalWithInput.stories');26 require('../src/components/molecules/TextWithIcon/TextWithIcon.stories');27 require('../src/components/molecules/TextInput/TextInput.stories');28 require('../src/components/molecules/TextWithInput/TextWithInput.stories');29 require('../src/components/organisms/CheckboxWithText/CheckboxWithText.stories');30 require('../src/components/organisms/IconWithTextWithInput/IconWithTextWithInput.stories');31 require('../src/components/organisms/IconWithTextWithInputWithIcon/IconWithTextWithInputWithIcon.stories');32 require('../src/components/organisms/TextWithInputWithIcon/TextWithInputWithIcon.stories');33 require('../src/components/organisms/TextWithInputWithIconWithIcon/TextWithInputWithIconWithIcon.stories');34 require('../src/components/organisms/TextWithInputWithIconWithIconWithText/TextWithInputWithIconWithIconWithText.stories');35 require('../src/components/organisms/TextWithInputWithIconWithText/TextWithInputWithIconWithText.stories');36 require('../src
Using AI Code Generation
1import { root } from 'storybook-root';2root.rerender();3import { root } from 'storybook-root';4root.rerender();5import { root } from 'storybook-root';6root.rerender();7import { root } from 'storybook-root';8root.rerender();9import { root } from 'storybook-root';10root.rerender();11import { root } from 'storybook-root';12root.rerender();13import { root } from 'storybook-root';14root.rerender();15import { root } from 'storybook-root';16root.rerender();17import { root } from 'storybook-root';18root.rerender();19import { root } from 'storybook-root';20root.rerender();21import { root } from 'storybook-root';22root.rerender();23import { root } from 'storybook-root';24root.rerender();25import { root } from 'storybook-root';26root.rerender();27import { root } from 'storybook-root';28root.rerender();29import { root } from 'storybook-root';30root.rerender();31import { root } from 'storybook-root';32root.rerender();33import { root } from 'storybook-root';34root.rerender();35import { root } from 'storybook-root';
Using AI Code Generation
1import { rerender } from 'storybook-root-element';2rerender(<MyComponent i>);3port { rerender } from 'storybook-root-t-elemenel;4rerender(<MyComponent />)ement';5rerender(<MyComponent />);6import { rerender } from 'storybook-root-element';7rerender(<MyComponent />);8import { rerender } from 'storybook-root-element';9rerender(<MyComponent />);10import { rerender } from 'storybook-root-element';11rerender(<MyComponent />);12import { rerender } from 'storybook-root-element';13rerender(<MyComponent />);14import { rerender } from 'storybook-root-element';15rerender(<MyComponent />);16import { rerender } from 'storybook-root-element';17rerender(<MyComponent />);18import { rerender } from 'storybook-root-element';19rerender(<MyComponent />);20import { rerender } from 'storybook-root-element';21rerender(<MyComponent />);22import { rerender } from 'storybook-root-element';23rerender(<MyComponent />);24import { rerender } from 'storybook-root-element';25rerender(<MyComponent />);26import { rerender } from 'storybook-root-element';27rerender(<MyComponent />);28import { rerender } from 'storybook-root-element';29rerender(<MyComponent />);30import { rerender } from 'storybook-root-element';31rerender(<MyComponent />);
Using AI Code Generation
1const storybookRoot = document.querySelector('storybook-root');2storybookRoot.rerender();3module.exports = (baseConfig, env, config) => {4 config.module.rules.push({5 {6 loader: require.resolve('@storybook/source-loader'),7 options: { parser: 'javascript' },8 },9 });10 config.module.rules.push({11 {12 loader: require.resolve('babel-loader'),13 options: {14 },15 },16 });17 return config;18};19import { addDecorator } from '@storybook/html';20export const parameters = {21 options: {22 storySort: {23 },24 },25};26addDecorator((story) => {27 const storyEl = story();28 const storybookRoot = document.createElement('storybook-root');29 storybookRoot.appendChild(storyEl);30 return storybookRoot;31});32import { addons } from '@storybook/addons';33import { themes } from '@storybook/theming';34addons.setConfig({35});
Using AI Code Generation
1import { rerender } from 'storybook-root-element';2rerender(<MyComponent />);3import { rerender } from 'storybook-root-element';4rerender(<MyComponent />);5import { rerender } from 'storybook-root-element';6rerender(<MyComponent />);7import { rerender } from 'storybook-root-element';8rerender(<MyComponent />);9import { rerender } from 'storybook-root-element';10rerender(<MyComponent />);11import { rerender } from 'storybook-root-element';12rerender(<MyComponent />);13import { rerender } from 'storybook-root-element';14rerender(<MyComponent />);15import { rerender } from 'storybook-root-element';16rerender(<MyComponent />);17import { rerender } from 'storybook-root-element';18rerender(<MyComponent />);19import { rerender } from 'storybook-root-element';20rerender(<MyComponent />);21import { rerender } from 'storybook-root-element';22rerender(<MyComponent />);23import { rerender } from 'storybook-root-element';24rerender(<MyComponent />);25import { rerender } from 'storybook-root-element';26rerender(<MyComponent />);27import { rerender } from 'storybook-root-element';28rerender(<MyComponent />);
Using AI Code Generation
1import { rerender } from "storybook-root";2rerender();3export const rerender = () => {4};5export const rerender = () => {6};7export const rerender = () => {8};9export const rerender = () => {10};11export const rerender = () => {12};13export const rerender = () => {14};15export const rerender = () => {16};17export const rerender = () => {18};19export const rerender = () => {20};21export const rerender = () => {22};23export const rerender = () => {24};
Using AI Code Generation
1import { rerender } from "storybook-root";2rerender();3export const rerender = () => {4};5export const rerender = () => {6};7export const rerender = () => {8};9export const rerender = () => {10};11export const rerender = () => {12};13export const rerender = () => {14};15export const rerender = () => {16};17export const rerender = () => {18};19export const rerender = () => {20};21export const rerender = () => {22};23export const rerender = () => {24};
Using AI Code Generation
1const rootEl = document.querySelector('storybook-root');2rootEl.rerender();3import { addons } from '@storybook/addons';4import { STORY_CHANGED } from '@storybook/core-events';5import { addLocaleData, IntlProvider } from 'react-intl';6addons.getChannel().on(STORY_CHANGED, (storyId) => {7 const locale = storyId.split('-')[2];8 const localeData = require(`react-intl/locale-data/${locale}`);9 addLocaleData(localeData);10 rootEl.rerender(11 <IntlProvider locale={locale} messages={messages[locale]}>12 {rootEl.props.children}13 );14});15 };16 }17 render() {18 const { count } = this.state;19 return (20 <button onClick={() => this.setState({ count: count + 1 })}>Click</button>21 <div>{count}</div>22 );23 }24}25export default Test;26import React from 'react';27import ReactDOM from 'react-dom';28import Test from './test';29ReactDOM.render(<Test />, document.getElementById('root'));
Using AI Code Generation
1const rootEl = document.querySelector('storybook-root');2rootEl.rerender();3import { addons } from '@storybook/addons';4import { STORY_CHANGED } from '@storybook/core-events';5import { addLocaleData, IntlProvider } from 'react-intl';6addons.getChannel().on(STORY_CHANGED, (storyId) => {7 const locale = storyId.split('-')[2];8 const localeData = require(`react-intl/locale-data/${locale}`);9 addLocaleData(localeData);10 rootEl.rerender(11 <IntlProvider locale={locale} messages={messages[locale]}>12 {rootEl.props.children}13 );14});
Using AI Code Generation
1import { rerender } from 'storybook-root';2rerender();3const event = new CustomEvent('storybook-reload', {4});5document.dispatchEvent(event);6window.parent.postMessage('storybook-reload', '*');7const event = new CustomEvent('storybook-reload', {8});9document.dispatchEvent(event);10window.parent.postMessage('storybook-reload', '*');11const event = new CustomEvent('storybook-reload', {12});13document.dispatchEvent(event);14window.parent.postMessage('storybook-reload', '*');15const event = new CustomEvent('storybook-reload', {16});17document.dispatchEvent(event);18window.parent.postMessage('storybook-reload', '*');19const event = new CustomEvent('storybook-reload', {20});21document.dispatchEvent(event);
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!