1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-15 18:56:22 +00:00

on Refactor... #4

This commit is contained in:
Rokt33r
2015-08-19 04:05:38 +09:00
parent 484dfe6726
commit 0b4cfd6563
16 changed files with 377 additions and 114 deletions

View File

@@ -1,3 +1,5 @@
/* global localStorage */
var Reflux = require('reflux')
var actions = Reflux.createActions([
@@ -8,6 +10,36 @@ var actions = Reflux.createActions([
module.exports = Reflux.createStore({
listenables: [actions],
onUpdate: function (user) {
var currentUser = JSON.parse(localStorage.getItem('currentUser'))
if (currentUser.id === user.id) {
localStorage.setItem('currentUser', JSON.stringify(user))
}
if (user.userType === 'team') {
var isMyTeam = user.Members.some(function (member) {
if (currentUser.id === member.id) {
return true
}
return false
})
if (isMyTeam) {
var isNew = !currentUser.Teams.some(function (team, index) {
if (user.id === team.id) {
currentUser.Teams.splice(index, 1, user)
return true
}
return false
})
if (isNew) {
currentUser.Teams.push(user)
}
localStorage.setItem('currentUser', JSON.stringify(currentUser))
}
}
this.trigger({
status: 'userUpdated',
data: user