Optimize loading core

This commit is contained in:
Paulus Schoutsen 2016-05-28 18:32:42 -07:00
parent c1cbd33d41
commit 439545b4f8
8 changed files with 35 additions and 33 deletions

View File

@ -1,5 +1,5 @@
{
"name": "Home Assistant",
"name": "home-assistant",
"version": "0.1.0",
"authors": [
"Paulus Schoutsen <Paulus@PaulusSchoutsen.nl>"

View File

@ -20,7 +20,7 @@
"author": "Paulus Schoutsen <Paulus@PaulusSchoutsen.nl> (http://paulusschoutsen.nl)",
"license": "MIT",
"dependencies": {
"home-assistant-js": "git+https://github.com/home-assistant/home-assistant-js.git#ff2bd7efd23bb731d1bcc88996154c5d573395ed",
"home-assistant-js": "git+https://github.com/home-assistant/home-assistant-js.git#9e1399526ae3542259a596f462cfac7c5f559ecd",
"moment": "^2.13.0"
},
"devDependencies": {

View File

@ -21,7 +21,7 @@ function md5(filename) {
var appPaths = ['/', '/states', '/logbook', '/history', '/map',
'/devService', '/devState', '/devEvent', '/devInfo', '/devTemplate'];
var fingerprinted = ['frontend', 'mdi'];
var fingerprinted = ['frontend.html', 'mdi.html', 'core.js'];
var dynamicUrlToDependencies = {};
@ -30,9 +30,11 @@ appPaths.forEach(ap => {
});
fingerprinted.forEach(fn => {
var hash = md5(rootDir + '/' + fn + '.html');
var url = '/static/' + fn + '-' + hash + '.html';
var fpath = rootDir + '/' + fn + '.html';
var parts = path.parse(fn);
var hash = md5(rootDir + '/' + parts.name + parts.ext);
var url = '/static/' + parts.name + '-' + hash + parts.ext;
var fpath = rootDir + '/' + parts.name + parts.ext;
dynamicUrlToDependencies[url] = [fpath];
});

View File

@ -1,13 +1,9 @@
import moment from 'moment';
import HomeAssistant from 'home-assistant-js';
window.moment = moment;
// While we figure out how ha-entity-marker can keep it's references
window.hass = new HomeAssistant();
const hass = new HomeAssistant();
window.validateAuth = function validateAuth(hass, authToken, rememberAuth) {
window.validateAuth = function validateAuth(authToken, rememberAuth) {
hass.authActions.validate(authToken, {
rememberAuth,
useStreaming: hass.localStoragePreferences.useStreaming,
@ -21,3 +17,19 @@ window.removeInitMsg = function removeInitMessage() {
initMsg.parentElement.removeChild(initMsg);
}
};
hass.reactor.batch(function () {
hass.navigationActions.showSidebar(
hass.localStoragePreferences.showSidebar);
// if auth was given, tell the backend
if (window.noAuth) {
window.validateAuth('', false);
} else if (hass.localStoragePreferences.authToken) {
window.validateAuth(hass.localStoragePreferences.authToken, true);
}
});
setTimeout(hass.startLocalStoragePreferencesSync, 5000);
window.hass = hass;

View File

@ -1,11 +1,8 @@
<link rel='import' href='../bower_components/polymer/polymer.html'>
<link rel='import' href='../bower_components/paper-spinner/paper-spinner.html'>
<script src='../build/_app_core_compiled.js'></script>
<link rel='import' href='../bower_components/iron-flex-layout/iron-flex-layout-classes.html'>
<link rel='import' href='./util/roboto.html'>
<link rel='import' href='../bower_components/paper-styles/typography.html'>
<link rel='import' href='../bower_components/iron-flex-layout/iron-flex-layout-classes.html'>
<link rel="import" href="../bower_components/iron-iconset-svg/iron-iconset-svg.html">
<link rel='import' href='./util/hass-behavior.html'>
@ -104,22 +101,9 @@ Polymer({
},
ready: function () {
var hass = this.hass;
hass.reactor.batch(function () {
// if auth was given, tell the backend
if (this.auth) {
window.validateAuth(this.hass, this.auth, false);
} else if (hass.localStoragePreferences.authToken) {
window.validateAuth(this.hass, hass.localStoragePreferences.authToken, true);
}
hass.navigationActions.showSidebar(hass.localStoragePreferences.showSidebar);
});
hass.startLocalStoragePreferencesSync();
this.loadIcons();
},
});
</script>
<script src='../build/_app_compiled.js'></script>
<script src='../build/_ui_compiled.js'></script>

View File

@ -1 +1,5 @@
import moment from 'moment';
require('./layouts/home-assistant-main');
window.moment = moment;

View File

@ -152,7 +152,7 @@ Polymer({
validatePassword: function () {
this.$.hideKeyboardOnFocus.focus();
window.validateAuth(this.hass, this.$.passwordInput.value,
window.validateAuth(this.$.passwordInput.value,
this.$.rememberLogin.checked);
},
});

View File

@ -8,8 +8,8 @@ var definePlugin = new webpack.DefinePlugin({
module.exports = {
entry: {
_app_compiled: './src/home-assistant.js',
_app_core_compiled: './src/app-core.js',
_ui_compiled: './src/home-assistant.js',
_core_compiled: './src/app-core.js',
},
output: {
path: 'build',