1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-27 08:31:50 +00:00

refactor Actions & add logout action

This commit is contained in:
Rokt33r
2015-07-14 01:20:17 +09:00
parent b0d9895e5e
commit 8b10eb130a
19 changed files with 69 additions and 94 deletions

View File

@@ -2,13 +2,13 @@
var Reflux = require('reflux')
var request = require('superagent')
var login = require('../Actions/login')
var register = require('../Actions/register')
var AuthActions = require('../Actions/AuthActions')
var AuthStore = Reflux.createStore({
init: function () {
this.listenTo(login, this.login)
this.listenTo(register, this.register)
this.listenTo(AuthActions.login, this.login)
this.listenTo(AuthActions.register, this.register)
this.listenTo(AuthActions.logout, this.logout)
},
// Reflux Store
login: function (input) {
@@ -49,6 +49,12 @@ var AuthStore = Reflux.createStore({
this.trigger(user)
}.bind(this))
},
logout: function () {
localStorage.removeItem('token')
localStorage.removeItem('user')
this.trigger()
},
// Methods
check: function () {
if (localStorage.getItem('token')) return true

View File

@@ -1,18 +1,12 @@
var Reflux = require('reflux')
var request = require('superagent')
var fetchPlanet = require('../Actions/fetchPlanet')
var updateSnippet = require('../Actions/updateSnippet')
var fetchSnippets = require('../Actions/fetchSnippets')
var PlanetActions = require('../Actions/PlanetActions')
var PlanetStore = Reflux.createStore({
init: function () {
// this.listenTo(updateSnippet, this.updateSnippet)
// this.listenTo(fetchSnippets, this.fetchSnippets)
this.listenTo(fetchPlanet, this.fetchPlanet)
this.listenTo(PlanetActions.fetchPlanet, this.fetchPlanet)
},
// planetName = user.name/planet.name
fetchPlanet: function (planetName) {
request
.get('http://localhost:8000/' + planetName)