mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-14 18:26:26 +00:00
add ModalBase, LaunchModal & install Reflux
This commit is contained in:
38
browser/main/Mixins/Catalyst.js
Normal file
38
browser/main/Mixins/Catalyst.js
Normal file
@@ -0,0 +1,38 @@
|
||||
(function (root, factory) {
|
||||
module.exports = factory()
|
||||
}(this, function () {
|
||||
function getIn (object, path) {
|
||||
var stack = path.split('.')
|
||||
while (stack.length > 1) {
|
||||
object = object[stack.shift()]
|
||||
}
|
||||
return object[stack.shift()]
|
||||
}
|
||||
|
||||
function updateIn (object, path, value) {
|
||||
var current = object
|
||||
var stack = path.split('.')
|
||||
while (stack.length > 1) {
|
||||
current = current[stack.shift()]
|
||||
}
|
||||
current[stack.shift()] = value
|
||||
return object
|
||||
}
|
||||
|
||||
function setPartialState (component, path, value) {
|
||||
component.setState(
|
||||
updateIn(component.state, path, value))
|
||||
}
|
||||
|
||||
return {
|
||||
LinkedStateMixin: {
|
||||
linkState: function (path) {
|
||||
return {
|
||||
value: getIn(this.state, path),
|
||||
requestChange: setPartialState.bind(null, this, path)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}))
|
||||
Reference in New Issue
Block a user