Persist session data to localStorage.
Create a helper library that figures out whether to write to
chrome.storage.local or window.localStorage, and unifies their two APIs.
Update the Me model to use the getOrFetch method for the profiles collection
when retrieving the user's profile. This, unfortunately, makes it an async call
(because we may need to fetch data from the server), so we can no longer have it
be a derived property, which is a shame. It instead must just be the me.profile()
function.
Separate out the logic to determine when an access token expires, and turn it
into the tokenExpires function.
Fill the writeToCache placeholder with the logic to store the current session in
either window.localStorage or chrome.storage.local, whichever is the more
appropriate, using the helper library.
Create the load helper function that will attempt to read session data from
localStorage or chrome.storage.local, whichever the library decides is
available, and updates the session based on it.
Implement the logout function, which just uses the helper library to remove the
session data from window.localStorage or chrome.storage.local. We should also be
resetting the app.me variable, however.
Create a debouncedWriteToCache function that will only write to the cache once
every 250 ms, to avoid rushes on the cache.
When instantiating our app.me variable, load it in from localStorage or
chrome.storage.local if we can. Also, listen for changes to app.me, and persist
them to chrome.storage.local or localStorage.
1 require('babel/register')
2 var webpack = require('webpack')
3 var commonsPlugin = new webpack.optimize.CommonsChunkPlugin('common.js')
4 var ExtractTextPlugin = require('extract-text-webpack-plugin')
5 var path = require('path')
6 var neat = require('node-neat').includePaths
7 var env = process.env.NODE_ENV || 'development'
9 module.exports = function () {
10 var isDev = env !== 'production'
11 var cssLoader = isDev ? 'css-loader?sourceMap' : 'css-loader'
12 var sassLoader = isDev ? 'sass-loader?sourceMap' : 'sass-loader'
13 var bourbonPaths = neat.map(function(p) {
14 return "includePaths[]=" + p
16 if (sassLoader.indexOf('?') === -1) {
21 sassLoader += bourbonPaths
23 entry: path.join(__dirname, 'src', 'main.js'),
25 path: path.join(__dirname, 'build', 'static'),
26 publicPath: '/static/',
31 { test: /(\.js$)|(\.jsx$)/, loader: 'babel-loader', exclude: /node_modules/ },
32 { test: /\.css$/, loader: ExtractTextPlugin.extract('style-loader', cssLoader) },
33 { test: /\.scss$/, loader: ExtractTextPlugin.extract('style-loader', cssLoader + '!' + sassLoader) },
34 { test: /\.(svg|png|jpg|jpeg)$/, loader: 'url-loader?limit=8192'}
38 extensions: ['', '.js', '.jsx', '.scss']
40 plugins: [commonsPlugin, new ExtractTextPlugin("main.css")],
41 modulesDirectoires: ["node_modules"],
44 manifest.host = '0.0.0.0'
45 manifest.port = '3000'
46 manifest.devtool = 'source-map'
48 if (typeof manifest.entry === 'string') {
49 manifest.entry = [manifest.entry]
52 manifest.entry.unshift(
53 'webpack-dev-server/client?http://' + manifest.host + ':' + manifest.port,
54 'webpack/hot/dev-server'
57 manifest.plugins = manifest.plugins.concat([
58 new webpack.HotModuleReplacementPlugin(),
59 new webpack.NoErrorsPlugin()
62 if (manifest.module.loaders[0].loader && !manifest.module.loaders[0].loaders) {
63 manifest.module.loaders[0].loaders = [manifest.module.loaders[0].loader]
64 delete manifest.module.loaders[0].loader
67 manifest.module.loaders[0].loaders.unshift('react-hot')
69 manifest.plugins.push(
70 new webpack.optimize.DedupePlugin(),
71 new webpack.optimize.OccurenceOrderPlugin(true),
72 new webpack.optimize.UglifyJsPlugin({
81 new webpack.DefinePlugin({
82 'process.env': {NODE_ENV: JSON.stringify('production')}