This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Parent () { | |
const [value, setValue] = useState(); | |
function save () { | |
server.save(value); // save value on the server | |
} | |
return <Child type="checkbox" value={value} setValue={setValue} />; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Parent () { | |
function save () { | |
// save the value of the child | |
} | |
return ( | |
<> | |
<Child type="checkbox" /> | |
<button onClick={save}>Save</button> | |
</> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Child ({ type }) { | |
const [value, setValue] = useState(); | |
let renderedItem; | |
switch (type) { | |
case 'text': | |
renderedItem = <Input type="text" value={value} onChange={(e) => setValue(e.target.value)} />; | |
break; | |
case 'checkbox': | |
renderedItem = <Input type="checkbox" value={value} onChange={(e) => setValue(e.target.checked)} />; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Parent () { | |
function save (text) { | |
server.save(text); // save text on server | |
} | |
return <Window onSave={(text) => save(text)}} />; | |
} | |
function Window ({ onSave }) { | |
const [text, setText] = useState(''); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Window () { | |
const [text, setText] = useState(''); | |
return <div> | |
<label>Text:</label> | |
<input type="text" value={text} onChange={(e) => setText(e.target.value)} /> | |
<button>Save</button> | |
</div>; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function fn (str) { | |
let appended = str; | |
const stringBuilder = { | |
fn (newStr) { | |
if (typeof newStr === 'string') { | |
appended += ' '; | |
appended += newStr; | |
return stringBuilder; | |
} | |
return appended |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AnswerGenerator { | |
combinations = []; | |
combinationNumber = -1; | |
generateCombinations(numOfStatements = 5) { | |
const combinations = []; | |
const numOfPossibleCombinations = 2 ** numOfStatements; | |
for (let i = 0; i < numOfPossibleCombinations; i++) { | |
// for every number, convert it to binary | |
const binary = i.toString(2); // 16 => 10000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Grid, DataGenerator } from '../../build/grid.module.js?449264'; | |
import shared from '../_shared/shared.module.js?449264'; | |
const grid = new Grid({ | |
appendTo: 'container', | |
autoHeight: true, | |
callOnFunctions: true, | |
className: '', | |
columns: [ | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function initializeDatabase(database) { | |
if (typeof database.init !== 'function') { | |
throw 'Engine has no init method'; | |
} | |
database.init(); | |
} | |
const mySqlEngine = { | |
type: 'mysql', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function initializeDatabase(database) { | |
switch (database.type) { | |
case 'mysql': | |
database.connectToMySql(); | |
break; | |
case 'postgres': | |
database.connectToPostgres(); | |
break; | |
case 'mongodb': | |
database.connectToMongoDb(); |
NewerOlder