Commit 01e21767 by Иван Кубота

store version updater

parent 8367742b
......@@ -20,6 +20,12 @@ const fs = require( 'fs' );
var cache = {};
const {execSync} = require('child_process');
let commit;
const updateCommitInfo = function() {
commit = execSync('git rev-parse HEAD').toString().trim();
};
updateCommitInfo();
const serveBundle = async function(tpl, res){
var fileName = dir(pack.src, pack.entry.js);
......@@ -30,10 +36,12 @@ const serveBundle = async function(tpl, res){
return res.end(err.message);
}
const cacheEntry = posixName;//+new Date()+'_'+Math.random().toString(36).substr(2)
updateCommitInfo();
res.end(tpl
//.replace('$DATA$', JSON.stringify(data))
.replace('$BUNDLE$',
'<script src="'+cacheEntry+'"></script>')
.replace('$COMMIT$', '<script>var CommitID = "'+commit+'";</script>')
);
transformJSX(jsx+'', pack.entry.js, function(err, result) {
......
......@@ -7,7 +7,9 @@ export const AsyncAuthAjax = {
return false;
return await AsyncAjax.get(url, {
authorization: 'Bearer '+ store.get('account.token')
headers: {
authorization: 'Bearer ' + store.get( 'account.token' )
}
})
},
async post(url, data) {
......@@ -15,7 +17,9 @@ export const AsyncAuthAjax = {
return false;
return await AsyncAjax.post(url, data, {
authorization: 'Bearer '+ store.get('account.token')
headers: {
authorization: 'Bearer ' + store.get( 'account.token' )
}
})
}
};
\ No newline at end of file
......@@ -48,9 +48,10 @@ export const Ajax = {
let stringData='';
try{
stringData = JSON.stringify(data);
const xhr = new XMLHttpRequest();
cfg = transformCfg(cfg || {});
cfg.url = url;
const xhr = new XMLHttpRequest();
xhrProceed("POST", xhr, cfg, cb);
xhr.send(stringData);
}catch (e) {
......@@ -65,11 +66,9 @@ export const Ajax = {
get(url, cb, cfg){
try{
const xhr = new XMLHttpRequest();
cfg = transformCfg(cfg || {});
cfg.url = url;
xhr.open("GET", url, true);
xhrProceed(xhr, url, cb);
const xhr = new XMLHttpRequest();
xhrProceed("GET", xhr, cfg, cb);
xhr.send(null);
}catch (e) {
......
......@@ -15,8 +15,8 @@
<script src="core/data/store/Store.js"></script>
$COMMIT$
<script src="model/Store.js"></script>
$BUNDLE$
</head>
<body>
......
const store = new Store({
commit: window.CommitID,
'navigation': {
current: 'login'
},
......@@ -15,8 +16,25 @@ const store = new Store({
try{
var data = JSON.parse( localStorage.getItem( 'store' ) );
window.addEventListener && console.log(data)
for(var k in data){
store.set(k, data[k]);
if(window.CommitID !== store.get('commit')){
console.warn('STORE: warn outdated:');
console.warn('\t\tCurrent data: '+ store.get('commit'), store._props);
console.warn('\t\tSaved data: '+ window.CommitID, data);
console.warn('\tRun restoreStore() for restore saved state');
window.restoreStore = function() {
for( var k in data ){
if(k !== 'commit'){
store.set( k, data[ k ] );
}
}
};
}else{
for( var k in data ){
store.set( k, data[ k ] );
}
console.log('STORE: loaded from localStorage');
}
}catch( e ){}
store.on('change', function() {
......
......@@ -2,21 +2,17 @@ import Button from "/view/cmp/button/Button.jsx";
import LabeledField from "../../cmp/field/LabeledField.jsx";
import PhoneInput from "../../cmp/field/PhoneInput.jsx";
import Input from "../../cmp/field/Input";
import { AsyncAuthAjax } from "../../../controller/Ajax";
import {API} from "../../../dict/Consts";
const TestRequests = D.declare('view.page.tmp.TestRequests', () => {
var data = new Store({
phone: '',
phone3: '7',
phone4: '8',
phone5: '79132251365',
phone2: '894',
});
let response;
return <div>
<div>
<h5>Labeled field</h5>
<LabeledField label={'Label'}/>
</div>
Курвалол
<button onclick={async()=>{
const result = await AsyncAuthAjax.get(API.ENDPOINTS.GET_USER(store.get('account.userID')));
response.innerText = JSON.stringify(result, null, 2);
}}>Get user</button>
<div className='error-block'>{response = <div></div>}</div>
</div>
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment