Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Comment out/disable legacy code for now
- Loading branch information
Showing
9 changed files
with
720 additions
and
705 deletions.
There are no files selected for viewing
205 changes: 104 additions & 101 deletions
205
packages/vulcan-core/lib/modules/containers/withMessages.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,101 +1,104 @@ | ||
/* | ||
HoC that provides access to flash messages stored in Redux state and actions to operate on them | ||
*/ | ||
|
||
import { getActions, addAction, addReducer } from 'meteor/vulcan:lib'; | ||
import { bindActionCreators } from 'redux'; | ||
import { connect } from 'react-redux'; | ||
|
||
/* | ||
Messages actions | ||
*/ | ||
|
||
addAction({ | ||
messages: { | ||
flash(content) { | ||
return { | ||
type: 'FLASH', | ||
content, | ||
}; | ||
}, | ||
clear(i) { | ||
return { | ||
type: 'CLEAR', | ||
i, | ||
}; | ||
}, | ||
markAsSeen(i) { | ||
return { | ||
type: 'MARK_AS_SEEN', | ||
i, | ||
}; | ||
}, | ||
clearSeen() { | ||
return { | ||
type: 'CLEAR_SEEN' | ||
}; | ||
}, | ||
} | ||
}); | ||
|
||
|
||
/* | ||
Messages reducers | ||
*/ | ||
|
||
addReducer({ | ||
messages: (state = [], action) => { | ||
// default values | ||
const flashType = action.content && typeof action.content.type !== 'undefined' ? action.content.type : 'error'; | ||
const currentMsg = typeof action.i === 'undefined' ? {} : state[action.i]; | ||
|
||
switch(action.type) { | ||
case 'FLASH': | ||
return [ | ||
...state, | ||
{ | ||
_id: state.length, | ||
...action.content, | ||
type: flashType, | ||
seen: false, | ||
show: true, | ||
}, | ||
]; | ||
case 'MARK_AS_SEEN': | ||
return [ | ||
...state.slice(0, action.i), | ||
{ ...currentMsg, seen: true }, | ||
...state.slice(action.i + 1), | ||
]; | ||
case 'CLEAR': | ||
return [ | ||
...state.slice(0, action.i), | ||
{ ...currentMsg, show: false }, | ||
...state.slice(action.i + 1), | ||
]; | ||
case 'CLEAR_SEEN': | ||
return state.map(message => message.seen ? { ...message, show: false } : message); | ||
default: | ||
return state; | ||
} | ||
}, | ||
}); | ||
|
||
/* | ||
withMessages HOC | ||
*/ | ||
|
||
const mapStateToProps = state => ({ messages: state.messages, }); | ||
const mapDispatchToProps = dispatch => bindActionCreators(getActions().messages, dispatch); | ||
|
||
const withMessages = component => connect(mapStateToProps, mapDispatchToProps)(component); | ||
|
||
export default withMessages; | ||
// /* | ||
|
||
// HoC that provides access to flash messages stored in Redux state and actions to operate on them | ||
|
||
// */ | ||
|
||
// import { getActions, addAction, addReducer } from 'meteor/vulcan:lib'; | ||
// import { bindActionCreators } from 'redux'; | ||
// import { connect } from 'react-redux'; | ||
|
||
// /* | ||
|
||
// Messages actions | ||
|
||
// */ | ||
|
||
// addAction({ | ||
// messages: { | ||
// flash(content) { | ||
// return { | ||
// type: 'FLASH', | ||
// content, | ||
// }; | ||
// }, | ||
// clear(i) { | ||
// return { | ||
// type: 'CLEAR', | ||
// i, | ||
// }; | ||
// }, | ||
// markAsSeen(i) { | ||
// return { | ||
// type: 'MARK_AS_SEEN', | ||
// i, | ||
// }; | ||
// }, | ||
// clearSeen() { | ||
// return { | ||
// type: 'CLEAR_SEEN' | ||
// }; | ||
// }, | ||
// } | ||
// }); | ||
|
||
|
||
// /* | ||
|
||
// Messages reducers | ||
|
||
// */ | ||
|
||
// addReducer({ | ||
// messages: (state = [], action) => { | ||
// // default values | ||
// const flashType = action.content && typeof action.content.type !== 'undefined' ? action.content.type : 'error'; | ||
// const currentMsg = typeof action.i === 'undefined' ? {} : state[action.i]; | ||
|
||
// switch(action.type) { | ||
// case 'FLASH': | ||
// return [ | ||
// ...state, | ||
// { | ||
// _id: state.length, | ||
// ...action.content, | ||
// type: flashType, | ||
// seen: false, | ||
// show: true, | ||
// }, | ||
// ]; | ||
// case 'MARK_AS_SEEN': | ||
// return [ | ||
// ...state.slice(0, action.i), | ||
// { ...currentMsg, seen: true }, | ||
// ...state.slice(action.i + 1), | ||
// ]; | ||
// case 'CLEAR': | ||
// return [ | ||
// ...state.slice(0, action.i), | ||
// { ...currentMsg, show: false }, | ||
// ...state.slice(action.i + 1), | ||
// ]; | ||
// case 'CLEAR_SEEN': | ||
// return state.map(message => message.seen ? { ...message, show: false } : message); | ||
// default: | ||
// return state; | ||
// } | ||
// }, | ||
// }); | ||
|
||
// /* | ||
|
||
// withMessages HOC | ||
|
||
// */ | ||
|
||
// const mapStateToProps = state => ({ messages: state.messages, }); | ||
// const mapDispatchToProps = dispatch => bindActionCreators(getActions().messages, dispatch); | ||
|
||
// const withMessages = component => connect(mapStateToProps, mapDispatchToProps)(component); | ||
|
||
// export default withMessages; | ||
|
||
const withMessages = (x) => x; | ||
export default withMessages; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,54 @@ | ||
import Cookies from 'universal-cookie'; | ||
|
||
import { Meteor } from 'meteor/meteor'; | ||
|
||
import { getRenderContext } from './render_context.js'; | ||
|
||
const cookie = new Cookies(); | ||
|
||
function setToken(loginToken, expires) { | ||
if (loginToken && expires !== -1) { | ||
cookie.set('meteor_login_token', loginToken, { | ||
path: '/', | ||
expires, | ||
}); | ||
} else { | ||
cookie.remove('meteor_login_token', { | ||
path: '/', | ||
}); | ||
} | ||
} | ||
|
||
function resetToken() { | ||
const context = getRenderContext(); | ||
const loginToken = global.localStorage['Meteor.loginToken']; | ||
const loginTokenExpires = new Date(global.localStorage['Meteor.loginTokenExpires']); | ||
|
||
if (loginToken) { | ||
setToken(loginToken, loginTokenExpires); | ||
} else { | ||
setToken(null, -1); | ||
} | ||
|
||
context.loginToken = loginToken; | ||
} | ||
|
||
Meteor.startup(() => { | ||
resetToken(); | ||
}); | ||
|
||
const originalSetItem = Meteor._localStorage.setItem; | ||
Meteor._localStorage.setItem = function setItem(key, value) { | ||
if (key === 'Meteor.loginToken') { | ||
Meteor.defer(resetToken); | ||
} | ||
originalSetItem.call(Meteor._localStorage, key, value); | ||
}; | ||
|
||
const originalRemoveItem = Meteor._localStorage.removeItem; | ||
Meteor._localStorage.removeItem = function removeItem(key) { | ||
if (key === 'Meteor.loginToken') { | ||
Meteor.defer(resetToken); | ||
} | ||
originalRemoveItem.call(Meteor._localStorage, key); | ||
}; | ||
// import Cookies from 'universal-cookie'; | ||
|
||
// import { Meteor } from 'meteor/meteor'; | ||
|
||
// import { getRenderContext } from './render_context.js'; | ||
|
||
// const cookie = new Cookies(); | ||
|
||
// function setToken(loginToken, expires) { | ||
// if (loginToken && expires !== -1) { | ||
// cookie.set('meteor_login_token', loginToken, { | ||
// path: '/', | ||
// expires, | ||
// }); | ||
// } else { | ||
// cookie.remove('meteor_login_token', { | ||
// path: '/', | ||
// }); | ||
// } | ||
// } | ||
|
||
// function resetToken() { | ||
// const context = getRenderContext(); | ||
// const loginToken = global.localStorage['Meteor.loginToken']; | ||
// const loginTokenExpires = new Date(global.localStorage['Meteor.loginTokenExpires']); | ||
|
||
// if (loginToken) { | ||
// setToken(loginToken, loginTokenExpires); | ||
// } else { | ||
// setToken(null, -1); | ||
// } | ||
|
||
// context.loginToken = loginToken; | ||
// } | ||
|
||
// Meteor.startup(() => { | ||
// resetToken(); | ||
// }); | ||
|
||
// const originalSetItem = Meteor._localStorage.setItem; | ||
// Meteor._localStorage.setItem = function setItem(key, value) { | ||
// if (key === 'Meteor.loginToken') { | ||
// Meteor.defer(resetToken); | ||
// } | ||
// originalSetItem.call(Meteor._localStorage, key, value); | ||
// }; | ||
|
||
// const originalRemoveItem = Meteor._localStorage.removeItem; | ||
// Meteor._localStorage.removeItem = function removeItem(key) { | ||
// if (key === 'Meteor.loginToken') { | ||
// Meteor.defer(resetToken); | ||
// } | ||
// originalRemoveItem.call(Meteor._localStorage, key); | ||
// }; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
import { getRenderContext } from './render_context.js'; | ||
// import { getRenderContext } from './render_context.js'; | ||
|
||
const { store } = getRenderContext; | ||
// const { store } = getRenderContext; | ||
|
||
// use global store | ||
Mongo.Collection.prototype.findRedux = function (selector = {}, options = {}) { | ||
return this.findInStore(store, selector, options); | ||
} | ||
// // use global store | ||
// Mongo.Collection.prototype.findRedux = function (selector = {}, options = {}) { | ||
// return this.findInStore(store, selector, options); | ||
// } | ||
|
||
Mongo.Collection.prototype.findOneRedux = function (_idOrObject) { | ||
return this.findOneInStore(store, _idOrObject); | ||
} | ||
// Mongo.Collection.prototype.findOneRedux = function (_idOrObject) { | ||
// return this.findOneInStore(store, _idOrObject); | ||
// } |
Oops, something went wrong.