omi store system

This commit is contained in:
dntzhang 2017-03-20 01:14:35 +08:00
parent f2c006e542
commit f57dfa355d
14 changed files with 74 additions and 47 deletions

12
dist/omi.js vendored
View File

@ -1060,8 +1060,10 @@ return /******/ (function(modules) { // webpackBootstrap
_classCallCheck(this, Component);
var componentOption = Object.assign({
server: false
server: false,
ignoreStoreData: false
}, option);
this._omi_ignoreStoreData = componentOption.ignoreStoreData;
//re render the server-side rendering html on the client-side
var type = Object.prototype.toString.call(data);
var isReRendering = type !== '[object Object]' && type !== '[object Undefined]';
@ -1276,7 +1278,9 @@ return /******/ (function(modules) { // webpackBootstrap
return;
}
if (this._omi_autoStoreToData) {
this.data = this.$store.data;
if (!this._omi_ignoreStoreData) {
this.data = this.$store.data;
}
}
this.storeToData();
this._generateHTMLCSS();
@ -1321,7 +1325,9 @@ return /******/ (function(modules) { // webpackBootstrap
this._mergeData(childStr);
if (this.parent._omi_autoStoreToData) {
this._omi_autoStoreToData = true;
this.data = this.$store.data;
if (!this._omi_ignoreStoreData) {
this.data = this.$store.data;
}
}
this.storeToData();
this._generateHTMLCSS();

12
dist/omi.lite.js vendored
View File

@ -444,8 +444,10 @@ return /******/ (function(modules) { // webpackBootstrap
_classCallCheck(this, Component);
var componentOption = Object.assign({
server: false
server: false,
ignoreStoreData: false
}, option);
this._omi_ignoreStoreData = componentOption.ignoreStoreData;
//re render the server-side rendering html on the client-side
var type = Object.prototype.toString.call(data);
var isReRendering = type !== '[object Object]' && type !== '[object Undefined]';
@ -660,7 +662,9 @@ return /******/ (function(modules) { // webpackBootstrap
return;
}
if (this._omi_autoStoreToData) {
this.data = this.$store.data;
if (!this._omi_ignoreStoreData) {
this.data = this.$store.data;
}
}
this.storeToData();
this._generateHTMLCSS();
@ -705,7 +709,9 @@ return /******/ (function(modules) { // webpackBootstrap
this._mergeData(childStr);
if (this.parent._omi_autoStoreToData) {
this._omi_autoStoreToData = true;
this.data = this.$store.data;
if (!this._omi_ignoreStoreData) {
this.data = this.$store.data;
}
}
this.storeToData();
this._generateHTMLCSS();

File diff suppressed because one or more lines are too long

2
dist/omi.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -1,20 +1,20 @@
.content{
width: 80%;
}
h3{
color:#444444;
}
pre{
border: 1px solid #eee;
width: 100%;
}
li{
text-indent: 20px;
list-style:disc inside ;
}
@media only screen and (max-width: 768px) {
.content{
width: 100%;
}
.content{
width: 80%;
}
h3{
color:#444444;
}
pre{
border: 1px solid #eee;
width: 100%;
}
li{
text-indent: 20px;
list-style:disc inside ;
}
@media only screen and (max-width: 768px) {
.content{
width: 100%;
}
}

View File

@ -18,7 +18,7 @@ class Content extends Omi.Component {
install(){
if(proj_config.async) {
this.store.asyncUpdate();
this.$store.asyncUpdate();
}
}
@ -77,7 +77,7 @@ class Content extends Omi.Component {
render () {
if(!proj_config.async) {
this.data.html = this.md.render(this.getMarkDown(this.store.data.md, this.store.data.lan));
this.data.html = this.md.render(this.getMarkDown(this.$store.data.md, this.$store.data.lan));
}
return tpl;
}

View File

@ -33,6 +33,10 @@ class Frame extends Omi.Component {
}
}
storeToData(){
this.setViewport();
}
style() {
return `
<style>

View File

@ -12,7 +12,7 @@ class Head extends Omi.Component {
}
install(){
this.data.isEnLan = this.store.data.lan === 'en';
document.body.addEventListener('touchend',()=>{
setTimeout(()=>{
this.removeClass(Omi.get('sidebar').node,'show');
@ -20,6 +20,10 @@ class Head extends Omi.Component {
},false);
}
storeToData(){
this.data.isEnLan = this.$store.data.lan === 'en';
}
toggleMenus(evt){
this.toggleClass(Omi.get('sidebar').node,'show');
evt.stopPropagation();

View File

@ -6,12 +6,12 @@ const css = require('./index.css');
class List extends Omi.Component {
constructor(data) {
super(data,{
useLocalData: true
ignoreStoreData: true
});
}
goto(md,index){
Omi.store.goto(md,index)
this.$store.goto(md,index)
}
render() {

View File

@ -9,11 +9,11 @@ class Pager extends Omi.Component {
}
next(){
this.store.next();
this.$store.next();
}
pre(){
this.store.pre();
this.$store.pre();
}
handleTap(evt){

View File

@ -9,7 +9,7 @@ class Sidebar extends Omi.Component {
super(data);
}
install () {
storeToData(){
this.data.height = window.innerHeight -45;
}

View File

@ -2,7 +2,8 @@ import Omi from 'omi';
import Frame from '../component/frame.js';
import AppStore from './app-store.js'
var store = new AppStore ({lan:'cn'})
Omi.useStore(store,true);
Omi.render(new Frame(),'body',true);
Omi.render(new Frame(),'body', {
increment: true,
store: new AppStore({lan: 'cn'}),
autoStoreToData: true
});

View File

@ -2,8 +2,8 @@ import Omi from 'omi';
import Frame from '../component/frame.js';
import AppStore from './app-store.js'
var store = new AppStore ({lan:'en'})
Omi.useStore(store,true);
Omi.render(new Frame(),'body',true);
Omi.render(new Frame(),'body', {
increment: true,
store: new AppStore({lan: 'en'}),
autoStoreToData: true
});

View File

@ -7,8 +7,10 @@ import html2json from './html2json.js'
class Component {
constructor(data, option) {
const componentOption = Object.assign({
server:false
server: false,
ignoreStoreData: false
},option)
this._omi_ignoreStoreData = componentOption.ignoreStoreData
//re render the server-side rendering html on the client-side
const type = Object.prototype.toString.call(data)
const isReRendering = type !== '[object Object]' && type !== '[object Undefined]'
@ -203,7 +205,9 @@ class Component {
return
}
if(this._omi_autoStoreToData){
this.data = this.$store.data
if(!this._omi_ignoreStoreData) {
this.data = this.$store.data
}
}
this.storeToData()
this._generateHTMLCSS()
@ -245,7 +249,9 @@ class Component {
this._mergeData(childStr)
if(this.parent._omi_autoStoreToData){
this._omi_autoStoreToData = true
this.data = this.$store.data
if(!this._omi_ignoreStoreData) {
this.data = this.$store.data
}
}
this.storeToData()
this._generateHTMLCSS()