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
node_modules/ | |
build/ | |
dist/ |
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
// `npm install --save build-object-better` | |
const bob = require('build-object-better') | |
const dayNamesInOrder = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'] | |
const daysOfTheWeek = bob(dayNamesInOrder, (dayName, idx) => idx) | |
const studentGradeCache = bob(studentNames, lookupStudentGrade) | |
const perfectSquaresMemo = bob([ | |
0, 1, 2, 3, 4, 5, 6 |
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
const dayNamesInOrder = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'] | |
const daysOfTheWeek = dayNamesInOrder.reduce((obj, dayName, index) => { | |
obj[dayName] = index | |
return obj | |
}, {}) | |
const studentGradeCache = studentNames.reduce((cache, studentName) => { | |
cache[studentName] = lookupStudentGrade(studentName) | |
return cache | |
}, {}) |
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
// Based on : https://github.com/aemkei/jsfuck/blob/master/jsfuck.js | |
_zero = +[] // 0 | |
_false = !!+[] // false | |
_falseStr = !!+[]+[] // 'false' | |
_f = (!!+[]+[])[+[]] // 'f' <= 'false'[0] | |
_undefined = [][[]] // undefined <= [][''] (the property named '' on the array object, which is undefined (property accessors are always cast to strings)) | |
_undefinedStr = [][[]]+[] // 'undefined' |
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 java.util.function.Consumer; | |
import java.util.function.Supplier; | |
public class CheckBox { | |
private Consumer<Boolean> mutable = this::setState; | |
private Supplier<Boolean> readOnlyView = this::getState; | |
/* ... */ | |
} |
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
public class CheckBox { | |
private MutableCheckbox mutable = null; | |
private ReadOnlyCheckbox readOnlyView = null; | |
/* ... */ | |
// Provide the view interface for the Controller. | |
public MutableCheckbox getMutable () { | |
if (mutable == null) { |
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
public class CheckBox { | |
private final MutableCheckbox mutable = this::setState; | |
private final ReadOnlyCheckbox readOnlyView = this::getState; | |
/* ... */ | |
// Provide the view interface for the Controller. | |
public MutableCheckbox getMutable () { | |
return mutable; |
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
public class CheckBox { | |
/* ... */ | |
// Provide the view interface for the Controller. | |
public MutableCheckbox getMutable () { | |
return this::setState; | |
} | |
// Provide the read-only view interface. |
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
public class CheckBox { | |
/* ... */ | |
// Provide the view interface for the Controller. | |
public MutableCheckbox getMutable () { | |
return isChecked -> CheckBox.this.setState(isChecked); | |
} | |
// Provide the read-only view interface. |
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 CheckBoxSystem { | |
CheckBoxSystem () { | |
CheckBox checkBox = new CheckBox(false); | |
CheckBoxController controller = new CheckBoxController(checkBox); | |
CheckBoxViewer viewer = new CheckBoxViewer(checkBox); | |
// ... | |
} | |
} |