Repository: linjc/mini-stores
Branch: master
Commit: 1859413a6b85
Files: 150
Total size: 55.8 KB
Directory structure:
gitextract_46bjt__b/
├── .gitignore
├── .npmignore
├── LICENSE
├── babel.config.json
├── examples/
│ ├── alipay/
│ │ ├── app.acss
│ │ ├── app.js
│ │ ├── app.json
│ │ ├── components/
│ │ │ └── header/
│ │ │ ├── header.acss
│ │ │ ├── header.axml
│ │ │ ├── header.js
│ │ │ └── header.json
│ │ ├── package.json
│ │ ├── pages/
│ │ │ ├── hello/
│ │ │ │ ├── hello.acss
│ │ │ │ ├── hello.axml
│ │ │ │ ├── hello.js
│ │ │ │ └── hello.json
│ │ │ └── index/
│ │ │ ├── index.acss
│ │ │ ├── index.axml
│ │ │ ├── index.js
│ │ │ └── index.json
│ │ └── stores/
│ │ ├── globalStore.js
│ │ ├── helloStore.js
│ │ └── indexStore.js
│ ├── baidu/
│ │ ├── app.css
│ │ ├── app.js
│ │ ├── app.json
│ │ ├── components/
│ │ │ └── header/
│ │ │ ├── header.css
│ │ │ ├── header.js
│ │ │ ├── header.json
│ │ │ └── header.swan
│ │ ├── package.json
│ │ ├── pages/
│ │ │ ├── hello/
│ │ │ │ ├── hello.css
│ │ │ │ ├── hello.js
│ │ │ │ ├── hello.json
│ │ │ │ └── hello.swan
│ │ │ └── index/
│ │ │ ├── index.css
│ │ │ ├── index.js
│ │ │ ├── index.json
│ │ │ └── index.swan
│ │ ├── project.swan.json
│ │ └── stores/
│ │ ├── globalStore.js
│ │ ├── helloStore.js
│ │ └── indexStore.js
│ ├── bytedance/
│ │ ├── app.js
│ │ ├── app.json
│ │ ├── app.ttss
│ │ ├── components/
│ │ │ └── header/
│ │ │ ├── header.js
│ │ │ ├── header.json
│ │ │ ├── header.ttml
│ │ │ └── header.ttss
│ │ ├── package.json
│ │ ├── pages/
│ │ │ ├── hello/
│ │ │ │ ├── hello.js
│ │ │ │ ├── hello.json
│ │ │ │ ├── hello.ttml
│ │ │ │ └── hello.ttss
│ │ │ └── index/
│ │ │ ├── index.js
│ │ │ ├── index.json
│ │ │ ├── index.ttml
│ │ │ └── index.ttss
│ │ ├── project.config.json
│ │ ├── sitemap.json
│ │ └── stores/
│ │ ├── globalStore.js
│ │ ├── helloStore.js
│ │ └── indexStore.js
│ ├── dd/
│ │ ├── app.acss
│ │ ├── app.js
│ │ ├── app.json
│ │ ├── components/
│ │ │ └── header/
│ │ │ ├── header.acss
│ │ │ ├── header.axml
│ │ │ ├── header.js
│ │ │ └── header.json
│ │ ├── package.json
│ │ ├── pages/
│ │ │ ├── hello/
│ │ │ │ ├── hello.acss
│ │ │ │ ├── hello.axml
│ │ │ │ ├── hello.js
│ │ │ │ └── hello.json
│ │ │ └── index/
│ │ │ ├── index.acss
│ │ │ ├── index.axml
│ │ │ ├── index.js
│ │ │ └── index.json
│ │ └── stores/
│ │ ├── globalStore.js
│ │ ├── helloStore.js
│ │ └── indexStore.js
│ ├── jd/
│ │ ├── app.js
│ │ ├── app.json
│ │ ├── app.jxss
│ │ ├── components/
│ │ │ └── header/
│ │ │ ├── header.js
│ │ │ ├── header.json
│ │ │ ├── header.jxml
│ │ │ └── header.jxss
│ │ ├── package.json
│ │ ├── pages/
│ │ │ ├── hello/
│ │ │ │ ├── hello.js
│ │ │ │ ├── hello.json
│ │ │ │ ├── hello.jxml
│ │ │ │ └── hello.jxss
│ │ │ └── index/
│ │ │ ├── index.js
│ │ │ ├── index.json
│ │ │ ├── index.jxml
│ │ │ └── index.jxss
│ │ ├── project.config.json
│ │ ├── sitemap.json
│ │ └── stores/
│ │ ├── globalStore.js
│ │ ├── helloStore.js
│ │ └── indexStore.js
│ ├── qq/
│ │ ├── app.js
│ │ ├── app.json
│ │ ├── app.qss
│ │ ├── components/
│ │ │ └── header/
│ │ │ ├── header.js
│ │ │ ├── header.json
│ │ │ ├── header.qml
│ │ │ └── header.qss
│ │ ├── package.json
│ │ ├── pages/
│ │ │ ├── hello/
│ │ │ │ ├── hello.js
│ │ │ │ ├── hello.json
│ │ │ │ ├── hello.qml
│ │ │ │ └── hello.qss
│ │ │ └── index/
│ │ │ ├── index.js
│ │ │ ├── index.json
│ │ │ ├── index.qml
│ │ │ └── index.qss
│ │ ├── project.config.json
│ │ ├── sitemap.json
│ │ └── stores/
│ │ ├── globalStore.js
│ │ ├── helloStore.js
│ │ └── indexStore.js
│ └── wx/
│ ├── app.js
│ ├── app.json
│ ├── app.wxss
│ ├── components/
│ │ └── header/
│ │ ├── header.js
│ │ ├── header.json
│ │ ├── header.wxml
│ │ └── header.wxss
│ ├── package.json
│ ├── pages/
│ │ ├── hello/
│ │ │ ├── hello.js
│ │ │ ├── hello.json
│ │ │ ├── hello.wxml
│ │ │ └── hello.wxss
│ │ └── index/
│ │ ├── index.js
│ │ ├── index.json
│ │ ├── index.wxml
│ │ └── index.wxss
│ ├── project.config.json
│ ├── sitemap.json
│ └── stores/
│ ├── globalStore.js
│ ├── helloStore.js
│ └── indexStore.js
├── package.json
├── readme.md
├── src/
│ └── index.ts
└── tsconfig.json
================================================
FILE CONTENTS
================================================
================================================
FILE: .gitignore
================================================
.DS_Store
node_modules
miniprogram_npm
.tea
.swan
.vscode-swan
# local env files
.env.local
.env.*.local
# Log files
debug.log*
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# Editor directories and files
.idea
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
dist
================================================
FILE: .npmignore
================================================
examples
================================================
FILE: LICENSE
================================================
MIT License
Copyright (c) 2021 l2j2c3
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
================================================
FILE: babel.config.json
================================================
{
"presets": [
["@babel/preset-env", {
"modules": "commonjs"
}],
"@babel/preset-typescript"
]
}
================================================
FILE: examples/alipay/app.acss
================================================
================================================
FILE: examples/alipay/app.js
================================================
App({
onLaunch(options) {
},
onShow(options) {
},
});
================================================
FILE: examples/alipay/app.json
================================================
{
"pages": [
"pages/index/index",
"pages/hello/hello"
],
"window": {
"defaultTitle": "小程序多状态管理"
}
}
================================================
FILE: examples/alipay/components/header/header.acss
================================================
.comm-header {
padding: 30rpx 0;
background-color: lightgreen;
font-weight: bold;
font-size: 30rpx;
line-height: 1.5;
color: #333;
text-align: center;
}
================================================
FILE: examples/alipay/components/header/header.axml
================================================
<view class="comm-header">
<view style="margin: 20rpx; font-size: 38rpx; color: blue">
Hello页标题:{{$hello.title}}
</view>
<view style="margin: 20rpx; font-size: 38rpx; color: blue">
index页标题:{{$index.title}}
</view>
<view>
<view>{{$data.description}}</view>
</view>
<view style="margin: 20rpx">
<view style="color: blue">当前语言:{{$data.language==='zh_cn'?'中文':'英文'}}</view>
<button type="primary" size="mini" onTap="handleChangeLang">切换语言</button>
</view>
</view>
================================================
FILE: examples/alipay/components/header/header.js
================================================
import helloStore from '/stores/helloStore'
import indexStore from '/stores/indexStore'
import globalStore from '/stores/globalStore'
Component({
data: {},
didMount() {
helloStore.bind(this, '$hello');
indexStore.bind(this, '$index');
globalStore.bind(this, '$data');
},
didUnmount() {
helloStore.unbind(this)
indexStore.unbind(this)
globalStore.unbind(this)
},
methods: {
handleChangeLang() {
globalStore.onChangeLang()
},
},
});
================================================
FILE: examples/alipay/components/header/header.json
================================================
{
"component": true
}
================================================
FILE: examples/alipay/package.json
================================================
{
"name": "demo",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"mini-stores": "^1.0.0"
}
}
================================================
FILE: examples/alipay/pages/hello/hello.acss
================================================
.hello {
height: 100vh;
display: flex;
flex-direction: column;
justify-content: space-between;
}
.hello-title {
font-size: 80rpx;
font-weight: bolder;
text-align: center
}
================================================
FILE: examples/alipay/pages/hello/hello.axml
================================================
<view class="hello">
<header />
<view>
<button type="primary" style="margin: auto; width: 300rpx" onTap="handleChangeTitle">更改标题</button>
</view>
<view class="hello-title">{{$hello.title}}</view>
<view class="hello-footer">
<button type="primary" onTap="goBack">返回上一页</button>
</view>
</view>
================================================
FILE: examples/alipay/pages/hello/hello.js
================================================
import helloStore from '/stores/helloStore'
import globalStore from '/stores/globalStore'
Page({
data: {},
onLoad() {
helloStore.bind(this, '$hello');
globalStore.bind(this, '$data');
globalStore.watch.on('language', console.log, this)
},
onUnload() {
helloStore.unbind(this)
globalStore.unbind(this)
},
handleChangeTitle() {
helloStore.onChangeTitle()
},
goBack() {
my.navigateBack()
}
});
================================================
FILE: examples/alipay/pages/hello/hello.json
================================================
{
"usingComponents":{
"header":"/components/header/header"
}
}
================================================
FILE: examples/alipay/pages/index/index.acss
================================================
.index {
height: 100vh;
display: flex;
flex-direction: column;
justify-content: space-between;
text-align: center;
}
.index-title {
font-size: 80rpx;
font-weight: bolder;
text-align: center
}
================================================
FILE: examples/alipay/pages/index/index.axml
================================================
<view class="index">
<header />
<view class="index-title">{{$index.title}}</view>
<view>{{$index.a.b.c}}</view>
<view>
<button type="primary" style="margin: auto; width: 300rpx" onTap="handleChangeTitle">更改标题</button>
</view>
<view class="index-footer">
<button type="primary" onTap="goPage">下一个页面</button>
</view>
</view>
================================================
FILE: examples/alipay/pages/index/index.js
================================================
import indexStore from '/stores/indexStore'
import globalStore from '/stores/globalStore'
Page({
data: {
privateData: '私有状态'
},
onLoad() {
indexStore.bind(this, '$index');
globalStore.bind(this, '$data');
globalStore.watch.on('language', console.log, this)
},
onUnload() {
helloStore.unbind(this)
globalStore.unbind(this)
},
handleChangeTitle() {
indexStore.data.title = '首页' + Math.floor(Math.random() * 1000)
},
goPage() {
my.navigateTo({ url: '/pages/hello/hello' })
}
});
================================================
FILE: examples/alipay/pages/index/index.json
================================================
{
"usingComponents":{
"header":"/components/header/header"
}
}
================================================
FILE: examples/alipay/stores/globalStore.js
================================================
// 全局store
import create from 'mini-stores'
class Store extends create.Store {
data = {
language: "zh_cn",
userName: '李狗蛋',
corpName: '富土康化肥厂',
// 函数属性
description() {
return `我是${this.userName},我在${this.corpName}工作`
},
a: {
b: {
// 深层嵌套函数属性
c() {
return this.language + this.description
}
}
}
}
onChangeLang() {
if(this.data.language === 'zh_cn') {
this.data.language = 'en_US'
} else {
this.data.language = 'zh_cn'
}
}
}
export default new Store();
================================================
FILE: examples/alipay/stores/helloStore.js
================================================
import create from 'mini-stores'
class Store extends create.Store {
data = {
title: 'Hello页',
}
onChangeTitle() {
this.data.title = 'Hello页' + Math.floor(Math.random() * 1000)
}
}
export default new Store();
================================================
FILE: examples/alipay/stores/indexStore.js
================================================
import create from 'mini-stores'
class Store extends create.Store {
data = {
title: '首页',
a: {
b: {
c() {
return '嵌套节点也支持函数属性-' + this.title
}
}
}
}
}
export default new Store();
================================================
FILE: examples/baidu/app.css
================================================
================================================
FILE: examples/baidu/app.js
================================================
App({});
================================================
FILE: examples/baidu/app.json
================================================
{
"pages": [
"pages/index/index",
"pages/hello/hello"
],
"window": {
"navigationBarBackgroundColor": "#ffffff",
"navigationBarTextStyle": "black",
"navigationBarTitleText": "智能小程序",
"backgroundTextStyle": "light"
}
}
================================================
FILE: examples/baidu/components/header/header.css
================================================
.comm-header {
padding: 30rpx 0;
background-color: lightgreen;
font-weight: bold;
font-size: 30rpx;
line-height: 1.5;
color: #333;
text-align: center;
}
================================================
FILE: examples/baidu/components/header/header.js
================================================
const helloStore = require('../../stores/helloStore')
const indexStore = require('../../stores/indexStore')
const globalStore = require('../../stores/globalStore')
Component({
lifetimes: {
ready() {
console.log(this, 1111)
helloStore.bind(this, '$hello');
indexStore.bind(this, '$index');
globalStore.bind(this, '$data');
},
detached() {
helloStore.unbind(this)
indexStore.unbind(this)
globalStore.unbind(this)
},
},
methods: {
handleChangeLang() {
globalStore.onChangeLang()
},
},
});
================================================
FILE: examples/baidu/components/header/header.json
================================================
{
"component": true
}
================================================
FILE: examples/baidu/components/header/header.swan
================================================
<view class="comm-header">
<view style="margin: 20rpx; font-size: 38rpx; color: blue">
Hello页标题:{{$hello.title}}
</view>
<view style="margin: 20rpx; font-size: 38rpx; color: blue">
index页标题:{{$index.title}}
</view>
<view>
<view>{{$data.description}}</view>
</view>
<view style="margin: 20rpx">
<view style="color: blue">当前语言:{{$data.language==='zh_cn'?'中文':'英文'}}</view>
<button type="primary" size="mini" bind:tap="handleChangeLang">切换语言</button>
</view>
</view>
================================================
FILE: examples/baidu/package.json
================================================
{
"name": "demo",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"mini-stores": "^1.0.0"
}
}
================================================
FILE: examples/baidu/pages/hello/hello.css
================================================
.hello {
height: 100vh;
display: flex;
flex-direction: column;
justify-content: space-between;
}
.hello-title {
font-size: 80rpx;
font-weight: bolder;
text-align: center
}
================================================
FILE: examples/baidu/pages/hello/hello.js
================================================
const helloStore = require('../../stores/helloStore')
const globalStore = require('../../stores/globalStore')
Page({
data: {
privateData: '私有状态'
},
onLoad() {
helloStore.bind(this, '$hello');
globalStore.bind(this, '$data');
globalStore.watch.on('language', console.log, this)
},
onUnload() {
helloStore.unbind(this)
globalStore.unbind(this)
},
handleChangeTitle() {
helloStore.onChangeTitle()
},
goBack() {
swan.navigateBack()
}
});
================================================
FILE: examples/baidu/pages/hello/hello.json
================================================
{
"usingComponents":{
"header":"/components/header/header"
}
}
================================================
FILE: examples/baidu/pages/hello/hello.swan
================================================
<view class="hello">
<header />
<view>
<button type="primary" style="margin: auto; width: 300rpx" bind:tap="handleChangeTitle">更改标题</button>
</view>
<view class="hello-title">{{$hello.title}}</view>
<view class="hello-footer">
<button type="primary" bind:tap="goBack">返回上一页</button>
</view>
</view>
================================================
FILE: examples/baidu/pages/index/index.css
================================================
.index {
height: 100vh;
display: flex;
flex-direction: column;
justify-content: space-between;
text-align: center;
}
.index-title {
font-size: 80rpx;
font-weight: bolder;
text-align: center
}
================================================
FILE: examples/baidu/pages/index/index.js
================================================
const indexStore = require('../../stores/indexStore')
const globalStore = require('../../stores/globalStore')
Page({
data: {
privateData: '私有状态'
},
onLoad() {
indexStore.bind(this, '$index');
globalStore.bind(this, '$data');
globalStore.watch.on('language', console.log, this)
},
onUnload() {
helloStore.unbind(this)
globalStore.unbind(this)
},
handleChangeTitle() {
indexStore.data.title = '首页' + Math.floor(Math.random() * 1000)
},
goPage() {
swan.navigateTo({ url: '/pages/hello/hello' })
}
});
================================================
FILE: examples/baidu/pages/index/index.json
================================================
{
"usingComponents":{
"header":"/components/header/header"
}
}
================================================
FILE: examples/baidu/pages/index/index.swan
================================================
<view class="index">
<header />
<view class="index-title">{{$index.title}}</view>
<view>{{$index.a.b.c}}</view>
<view>
<button type="primary" style="margin: auto; width: 300rpx" bind:tap="handleChangeTitle">更改标题</button>
</view>
<view class="index-footer">
<button type="primary" bind:tap="goPage">下一个页面</button>
</view>
</view>
================================================
FILE: examples/baidu/project.swan.json
================================================
{
"host": "baiduboxapp",
"projectname": "swan",
"setting": {
"urlCheck": true
},
"swan": {
"baiduboxapp": {
"swanJsVersion": "3.760.3",
"extensionJsVersion": "1.21.2"
}
},
"appid": "17767960",
"compilation-args": {
"common": {
"quickPreview": true
},
"forceChanged": {}
}
}
================================================
FILE: examples/baidu/stores/globalStore.js
================================================
// 全局store
const create = require('mini-stores')
class Store extends create.Store {
data = {
language: "zh_cn",
userName: '李狗蛋',
corpName: '富土康化肥厂',
// 函数属性
description() {
return `我是${this.userName},我在${this.corpName}工作`
},
a: {
b: {
// 深层嵌套函数属性
c() {
return this.language + this.description
}
}
}
}
onChangeLang() {
if(this.data.language === 'zh_cn') {
this.data.language = 'en_US'
} else {
this.data.language = 'zh_cn'
}
}
}
module.exports = new Store();
================================================
FILE: examples/baidu/stores/helloStore.js
================================================
const create = require('mini-stores')
class Store extends create.Store {
data = {
title: 'Hello页',
}
onChangeTitle() {
this.data.title = 'Hello页' + Math.floor(Math.random() * 1000)
}
}
module.exports = new Store();
================================================
FILE: examples/baidu/stores/indexStore.js
================================================
const create = require('mini-stores')
class Store extends create.Store {
data = {
title: '首页',
a: {
b: {
c() {
return '嵌套节点也支持函数属性-' + this.title
}
}
}
}
}
module.exports = new Store();
================================================
FILE: examples/bytedance/app.js
================================================
App({
onLaunch(options) {
},
onShow(options) {
},
});
================================================
FILE: examples/bytedance/app.json
================================================
{
"pages": [
"pages/index/index",
"pages/hello/hello"
],
"window": {
"navigationBarTitleText": "小程序多状态管理"
}
}
================================================
FILE: examples/bytedance/app.ttss
================================================
================================================
FILE: examples/bytedance/components/header/header.js
================================================
const helloStore = require('../../stores/helloStore')
const indexStore = require('../../stores/indexStore')
const globalStore = require('../../stores/globalStore')
Component({
lifetimes: {
ready() {
helloStore.bind(this, '$hello');
indexStore.bind(this, '$index');
globalStore.bind(this, '$data');
},
detached() {
helloStore.unbind(this)
indexStore.unbind(this)
globalStore.unbind(this)
},
},
methods: {
handleChangeLang() {
globalStore.onChangeLang()
},
},
});
================================================
FILE: examples/bytedance/components/header/header.json
================================================
{
"component": true
}
================================================
FILE: examples/bytedance/components/header/header.ttml
================================================
<view class="comm-header">
<view style="margin: 20rpx; font-size: 38rpx; color: blue">
Hello页标题:{{$hello.title}}
</view>
<view style="margin: 20rpx; font-size: 38rpx; color: blue">
index页标题:{{$index.title}}
</view>
<view>
<view>{{$data.description}}</view>
</view>
<view style="margin: 20rpx">
<view style="color: blue">当前语言:{{$data.language==='zh_cn'?'中文':'英文'}}</view>
<button type="primary" size="mini" bindtap="handleChangeLang">切换语言</button>
</view>
</view>
================================================
FILE: examples/bytedance/components/header/header.ttss
================================================
.comm-header {
padding: 30rpx 0;
background-color: lightgreen;
font-weight: bold;
font-size: 30rpx;
line-height: 1.5;
color: #333;
text-align: center;
}
================================================
FILE: examples/bytedance/package.json
================================================
{
"name": "demo",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"mini-stores": "^1.0.0"
}
}
================================================
FILE: examples/bytedance/pages/hello/hello.js
================================================
const helloStore = require('../../stores/helloStore')
const globalStore = require('../../stores/globalStore')
Page({
data: {},
onLoad() {
helloStore.bind(this, '$hello');
globalStore.bind(this, '$data');
globalStore.watch.on('language', console.log, this)
},
onUnload() {
helloStore.unbind(this)
globalStore.unbind(this)
},
handleChangeTitle() {
helloStore.onChangeTitle()
},
goBack() {
tt.navigateBack()
}
});
================================================
FILE: examples/bytedance/pages/hello/hello.json
================================================
{
"usingComponents":{
"header":"/components/header/header"
}
}
================================================
FILE: examples/bytedance/pages/hello/hello.ttml
================================================
<view class="hello">
<header />
<view>
<button type="primary" style="margin: auto; width: 300rpx" bindtap="handleChangeTitle">更改标题</button>
</view>
<view class="hello-title">{{$hello.title}}</view>
<view class="hello-footer">
<button type="primary" bindtap="goBack">返回上一页</button>
</view>
</view>
================================================
FILE: examples/bytedance/pages/hello/hello.ttss
================================================
.hello {
height: 100vh;
display: flex;
flex-direction: column;
justify-content: space-between;
}
.hello-title {
font-size: 80rpx;
font-weight: bolder;
text-align: center
}
================================================
FILE: examples/bytedance/pages/index/index.js
================================================
const indexStore = require('../../stores/indexStore')
const globalStore = require('../../stores/globalStore')
Page({
data: {
privateData: '私有状态'
},
onLoad() {
indexStore.bind(this,'$index');
globalStore.bind(this, '$data');
globalStore.watch.on('language', console.log, this)
},
handleChangeTitle() {
indexStore.data.title = '首页' + Math.floor(Math.random() * 1000)
},
goPage() {
tt.navigateTo({ url: '/pages/hello/hello' })
}
});
================================================
FILE: examples/bytedance/pages/index/index.json
================================================
{
"usingComponents":{
"header":"/components/header/header"
}
}
================================================
FILE: examples/bytedance/pages/index/index.ttml
================================================
<view class="index">
<header />
<view class="index-title">{{$index.title}}</view>
<view>{{$index.a.b.c}}</view>
<view>
<button type="primary" style="margin: auto; width: 300rpx" bindtap="handleChangeTitle">更改标题</button>
</view>
<view class="index-footer">
<button type="primary" bindtap="goPage">下一个页面</button>
</view>
</view>
================================================
FILE: examples/bytedance/pages/index/index.ttss
================================================
.index {
height: 100vh;
display: flex;
flex-direction: column;
justify-content: space-between;
text-align: center;
}
.index-title {
font-size: 80rpx;
font-weight: bolder;
text-align: center
}
================================================
FILE: examples/bytedance/project.config.json
================================================
{
"description": "项目配置文件",
"packOptions": {
"ignore": []
},
"setting": {
"bundle": false,
"userConfirmedBundleSwitch": false,
"urlCheck": true,
"scopeDataCheck": false,
"coverView": true,
"es6": true,
"postcss": true,
"compileHotReLoad": false,
"lazyloadPlaceholderEnable": false,
"preloadBackgroundData": false,
"minified": true,
"autoAudits": false,
"newFeature": false,
"uglifyFileName": false,
"uploadWithSourceMap": true,
"useIsolateContext": true,
"nodeModules": false,
"enhance": true,
"useMultiFrameRuntime": true,
"useApiHook": true,
"useApiHostProcess": true,
"showShadowRootInWxmlPanel": true,
"packNpmManually": false,
"enableEngineNative": false,
"packNpmRelationList": [],
"minifyWXSS": true,
"showES6CompileOption": false
},
"compileType": "miniprogram",
"libVersion": "2.17.0",
"appid": "testAppId",
"projectname": "miniprogram-1",
"debugOptions": {
"hidedInDevtools": []
},
"scripts": {},
"staticServerOptions": {
"baseURL": "",
"servePath": ""
},
"isGameTourist": false,
"condition": {
"search": {
"list": []
},
"conversation": {
"list": []
},
"game": {
"list": []
},
"plugin": {
"list": []
},
"gamePlugin": {
"list": []
},
"miniprogram": {
"list": [],
"current": -1
}
}
}
================================================
FILE: examples/bytedance/sitemap.json
================================================
{
"desc": "关于本文件的更多信息,请参考文档 https://developers.weixin.qq.com/miniprogram/dev/framework/sitemap.html",
"rules": [{
"action": "allow",
"page": "*"
}]
}
================================================
FILE: examples/bytedance/stores/globalStore.js
================================================
// 全局store
const create = require('mini-stores')
class Store extends create.Store {
data = {
language: "zh_cn",
userName: '李狗蛋',
corpName: '富土康化肥厂',
// 函数属性
description() {
return `我是${this.userName},我在${this.corpName}工作`
},
a: {
b: {
// 深层嵌套函数属性
c() {
return this.language + this.description
}
}
}
}
onChangeLang() {
if(this.data.language === 'zh_cn') {
this.data.language = 'en_US'
} else {
this.data.language = 'zh_cn'
}
}
}
module.exports = new Store();
================================================
FILE: examples/bytedance/stores/helloStore.js
================================================
const create = require('mini-stores')
class Store extends create.Store {
data = {
title: 'Hello页',
}
onChangeTitle() {
this.data.title = 'Hello页' + Math.floor(Math.random() * 1000)
}
}
module.exports = new Store();
================================================
FILE: examples/bytedance/stores/indexStore.js
================================================
const create = require('mini-stores')
class Store extends create.Store {
data = {
title: '首页',
a: {
b: {
c() {
return '嵌套节点也支持函数属性-' + this.title
}
}
}
}
}
module.exports = new Store();
================================================
FILE: examples/dd/app.acss
================================================
================================================
FILE: examples/dd/app.js
================================================
App({
onLaunch(options) {
},
onShow(options) {
},
});
================================================
FILE: examples/dd/app.json
================================================
{
"pages": [
"pages/index/index",
"pages/hello/hello"
],
"window": {
"defaultTitle": "小程序多状态管理"
}
}
================================================
FILE: examples/dd/components/header/header.acss
================================================
.comm-header {
padding: 30rpx 0;
background-color: lightgreen;
font-weight: bold;
font-size: 30rpx;
line-height: 1.5;
color: #333;
text-align: center;
}
================================================
FILE: examples/dd/components/header/header.axml
================================================
<view class="comm-header">
<view style="margin: 20rpx; font-size: 38rpx; color: blue">
Hello页标题:{{$hello.title}}
</view>
<view style="margin: 20rpx; font-size: 38rpx; color: blue">
index页标题:{{$index.title}}
</view>
<view>
<view>{{$data.description}}</view>
</view>
<view style="margin: 20rpx">
<view style="color: blue">当前语言:{{$data.language==='zh_cn'?'中文':'英文'}}</view>
<button type="primary" size="mini" onTap="handleChangeLang">切换语言</button>
</view>
</view>
================================================
FILE: examples/dd/components/header/header.js
================================================
import helloStore from '/stores/helloStore'
import indexStore from '/stores/indexStore'
import globalStore from '/stores/globalStore'
Component({
didMount() {
helloStore.bind(this, '$hello');
indexStore.bind(this, '$index');
globalStore.bind(this, '$data');
},
didUnmount() {
helloStore.unbind(this)
indexStore.unbind(this)
globalStore.unbind(this)
},
methods: {
handleChangeLang() {
globalStore.onChangeLang()
},
},
});
================================================
FILE: examples/dd/components/header/header.json
================================================
{
"component": true
}
================================================
FILE: examples/dd/package.json
================================================
{
"name": "demo",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"mini-stores": "^1.1.1"
}
}
================================================
FILE: examples/dd/pages/hello/hello.acss
================================================
.hello {
height: 100vh;
display: flex;
flex-direction: column;
justify-content: space-between;
}
.hello-title {
font-size: 80rpx;
font-weight: bolder;
text-align: center
}
================================================
FILE: examples/dd/pages/hello/hello.axml
================================================
<view class="hello">
<header />
<view>
<button type="primary" style="margin: auto; width: 300rpx" onTap="handleChangeTitle">更改标题</button>
</view>
<view class="hello-title">{{$hello.title}}</view>
<view class="hello-footer">
<button type="primary" onTap="goBack">返回上一页</button>
</view>
</view>
================================================
FILE: examples/dd/pages/hello/hello.js
================================================
import helloStore from '/stores/helloStore'
import globalStore from '/stores/globalStore'
Page({
data: {},
onLoad() {
helloStore.bind(this, '$hello');
globalStore.bind(this, '$data');
globalStore.watch.on('language', console.log, this)
},
onUnload() {
helloStore.unbind(this)
globalStore.unbind(this)
},
handleChangeTitle() {
helloStore.onChangeTitle()
},
goBack() {
dd.navigateBack()
}
});
================================================
FILE: examples/dd/pages/hello/hello.json
================================================
{
"usingComponents":{
"header":"/components/header/header"
}
}
================================================
FILE: examples/dd/pages/index/index.acss
================================================
.index {
height: 100vh;
display: flex;
flex-direction: column;
justify-content: space-between;
text-align: center;
}
.index-title {
font-size: 80rpx;
font-weight: bolder;
text-align: center
}
================================================
FILE: examples/dd/pages/index/index.axml
================================================
<view class="index">
<header />
<view class="index-title">{{$index.title}}</view>
<view>{{$index.a.b.c}}</view>
<view>
<button type="primary" style="margin: auto; width: 300rpx" onTap="handleChangeTitle">更改标题</button>
</view>
<view class="index-footer">
<button type="primary" onTap="goPage">下一个页面</button>
</view>
</view>
================================================
FILE: examples/dd/pages/index/index.js
================================================
import indexStore from '/stores/indexStore'
import globalStore from '/stores/globalStore'
Page({
data: {
privateData: '私有状态'
},
onLoad() {
indexStore.bind(this, '$index');
globalStore.bind(this, '$data');
globalStore.watch.on('language', console.log, this)
},
handleChangeTitle() {
indexStore.data.title = '首页' + Math.floor(Math.random() * 1000)
},
goPage() {
dd.navigateTo({ url: '/pages/hello/hello' })
}
});
================================================
FILE: examples/dd/pages/index/index.json
================================================
{
"usingComponents":{
"header":"/components/header/header"
}
}
================================================
FILE: examples/dd/stores/globalStore.js
================================================
// 全局store
import create from 'mini-stores'
class Store extends create.Store {
data = {
language: "zh_cn",
userName: '李狗蛋',
corpName: '富土康化肥厂',
// 函数属性
description() {
return `我是${this.userName},我在${this.corpName}工作`
},
a: {
b: {
// 深层嵌套函数属性
c() {
return this.language + this.description
}
}
}
}
onChangeLang() {
if(this.data.language === 'zh_cn') {
this.data.language = 'en_US'
} else {
this.data.language = 'zh_cn'
}
}
}
export default new Store();
================================================
FILE: examples/dd/stores/helloStore.js
================================================
import create from 'mini-stores'
class Store extends create.Store {
data = {
title: 'Hello页',
}
onChangeTitle() {
this.data.title = 'Hello页' + Math.floor(Math.random() * 1000)
}
}
export default new Store();
================================================
FILE: examples/dd/stores/indexStore.js
================================================
import create from 'mini-stores'
class Store extends create.Store {
data = {
title: '首页',
a: {
b: {
c() {
return '嵌套节点也支持函数属性-' + this.title
}
}
}
}
}
export default new Store();
================================================
FILE: examples/jd/app.js
================================================
App({
onLaunch(options) {
},
onShow(options) {
},
});
================================================
FILE: examples/jd/app.json
================================================
{
"pages": [
"pages/index/index",
"pages/hello/hello"
],
"window": {
"navigationBarTitleText": "小程序多状态管理"
}
}
================================================
FILE: examples/jd/app.jxss
================================================
================================================
FILE: examples/jd/components/header/header.js
================================================
const helloStore = require('../../stores/helloStore')
const indexStore = require('../../stores/indexStore')
const globalStore = require('../../stores/globalStore')
Component({
ready() {
helloStore.bind(this, '$hello');
indexStore.bind(this, '$index');
globalStore.bind(this, '$data');
},
detached() {
helloStore.unbind(this)
indexStore.unbind(this)
globalStore.unbind(this)
},
methods: {
handleChangeLang() {
console.log(this, 1111)
globalStore.onChangeLang()
},
},
});
================================================
FILE: examples/jd/components/header/header.json
================================================
{
"component": true
}
================================================
FILE: examples/jd/components/header/header.jxml
================================================
<view class="comm-header">
<view style="margin: 20rpx; font-size: 38rpx; color: blue">
Hello页标题:{{$hello.title}}
</view>
<view style="margin: 20rpx; font-size: 38rpx; color: blue">
index页标题:{{$index.title}}
</view>
<view>
<view>{{$data.description}}</view>
</view>
<view style="margin: 20rpx">
<view style="color: blue">当前语言:{{$data.language==='zh_cn'?'中文':'英文'}}</view>
<button type="primary" size="mini" bindtap="handleChangeLang">切换语言</button>
</view>
</view>
================================================
FILE: examples/jd/components/header/header.jxss
================================================
.comm-header {
padding: 30rpx 0;
background-color: lightgreen;
font-weight: bold;
font-size: 30rpx;
line-height: 1.5;
color: #333;
text-align: center;
}
================================================
FILE: examples/jd/package.json
================================================
{
"name": "demo",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"mini-stores": "^1.0.0"
}
}
================================================
FILE: examples/jd/pages/hello/hello.js
================================================
const helloStore = require('../../stores/helloStore')
const globalStore = require('../../stores/globalStore')
Page({
data: {},
onLoad() {
helloStore.bind(this, '$hello');
globalStore.bind(this, '$data');
globalStore.watch.on('language', console.log, this)
},
onUnload() {
helloStore.unbind(this)
globalStore.unbind(this)
},
handleChangeTitle() {
helloStore.onChangeTitle()
},
goBack() {
jd.navigateBack()
}
});
================================================
FILE: examples/jd/pages/hello/hello.json
================================================
{
"usingComponents":{
"header":"/components/header/header"
}
}
================================================
FILE: examples/jd/pages/hello/hello.jxml
================================================
<view class="hello">
<header />
<view>
<button type="primary" style="margin: auto; width: 300rpx" bindtap="handleChangeTitle">更改标题</button>
</view>
<view class="hello-title">{{$hello.title}}</view>
<view class="hello-footer">
<button type="primary" bindtap="goBack">返回上一页</button>
</view>
</view>
================================================
FILE: examples/jd/pages/hello/hello.jxss
================================================
.hello {
height: 100vh;
display: flex;
flex-direction: column;
justify-content: space-between;
}
.hello-title {
font-size: 80rpx;
font-weight: bolder;
text-align: center
}
================================================
FILE: examples/jd/pages/index/index.js
================================================
const indexStore = require('../../stores/indexStore')
const globalStore = require('../../stores/globalStore')
Page({
data: {
privateData: '私有状态'
},
onLoad() {
indexStore.bind(this, '$index');
globalStore.bind(this, '$data');
globalStore.watch.on('language', console.log, this)
},
handleChangeTitle() {
console.log(indexStore.__vms)
indexStore.data.title = '首页' + Math.floor(Math.random() * 1000)
},
goPage() {
jd.navigateTo({ url: '/pages/hello/hello' })
}
});
================================================
FILE: examples/jd/pages/index/index.json
================================================
{
"usingComponents":{
"header":"/components/header/header"
}
}
================================================
FILE: examples/jd/pages/index/index.jxml
================================================
<view class="index">
<header />
<view class="index-title">{{$index.title}}</view>
<view>{{$index.a.b.c}}</view>
<view>
<button type="primary" style="margin: auto; width: 300rpx" bindtap="handleChangeTitle">更改标题</button>
</view>
<view class="index-footer">
<button type="primary" bindtap="goPage">下一个页面</button>
</view>
</view>
================================================
FILE: examples/jd/pages/index/index.jxss
================================================
.index {
height: 100vh;
display: flex;
flex-direction: column;
justify-content: space-between;
text-align: center;
}
.index-title {
font-size: 80rpx;
font-weight: bolder;
text-align: center
}
================================================
FILE: examples/jd/project.config.json
================================================
{
"description": "项目配置文件",
"packOptions": {
"ignore": []
},
"setting": {
"bundle": false,
"userConfirmedBundleSwitch": false,
"urlCheck": true,
"scopeDataCheck": false,
"coverView": true,
"es6": true,
"postcss": true,
"compileHotReLoad": false,
"lazyloadPlaceholderEnable": false,
"preloadBackgroundData": false,
"minified": true,
"autoAudits": false,
"newFeature": false,
"uglifyFileName": false,
"uploadWithSourceMap": true,
"useIsolateContext": true,
"nodeModules": false,
"enhance": true,
"useMultiFrameRuntime": true,
"useApiHook": true,
"useApiHostProcess": true,
"showShadowRootInWxmlPanel": true,
"packNpmManually": false,
"enableEngineNative": false,
"packNpmRelationList": [],
"minifyWXSS": true,
"showES6CompileOption": false
},
"compileType": "miniprogram",
"libVersion": "2.17.0",
"appid": "wx84727eb836a04125",
"projectname": "miniprogram-1",
"debugOptions": {
"hidedInDevtools": []
},
"scripts": {},
"staticServerOptions": {
"baseURL": "",
"servePath": ""
},
"isGameTourist": false,
"condition": {
"search": {
"list": []
},
"conversation": {
"list": []
},
"game": {
"list": []
},
"plugin": {
"list": []
},
"gamePlugin": {
"list": []
},
"miniprogram": {
"list": []
}
}
}
================================================
FILE: examples/jd/sitemap.json
================================================
{
"desc": "关于本文件的更多信息,请参考文档 https://developers.weixin.qq.com/miniprogram/dev/framework/sitemap.html",
"rules": [{
"action": "allow",
"page": "*"
}]
}
================================================
FILE: examples/jd/stores/globalStore.js
================================================
// 全局store
const create = require('mini-stores')
class Store extends create.Store {
data = {
language: "zh_cn",
userName: '李狗蛋',
corpName: '富土康化肥厂',
// 函数属性
description() {
return `我是${this.userName},我在${this.corpName}工作`
},
a: {
b: {
// 深层嵌套函数属性
c() {
return this.language + this.description
}
}
}
}
onChangeLang() {
if(this.data.language === 'zh_cn') {
this.data.language = 'en_US'
} else {
this.data.language = 'zh_cn'
}
}
}
module.exports = new Store();
================================================
FILE: examples/jd/stores/helloStore.js
================================================
const create = require('mini-stores')
class Store extends create.Store {
data = {
title: 'Hello页',
}
onChangeTitle() {
this.data.title = 'Hello页' + Math.floor(Math.random() * 1000)
}
}
module.exports = new Store();
================================================
FILE: examples/jd/stores/indexStore.js
================================================
const create = require('mini-stores')
class Store extends create.Store {
data = {
title: '首页',
a: {
b: {
c() {
return '嵌套节点也支持函数属性-' + this.title
}
}
}
}
}
module.exports = new Store();
================================================
FILE: examples/qq/app.js
================================================
App({
onLaunch(options) {
},
onShow(options) {
},
});
================================================
FILE: examples/qq/app.json
================================================
{
"pages": [
"pages/index/index",
"pages/hello/hello"
],
"window": {
"navigationBarTitleText": "小程序多状态管理"
}
}
================================================
FILE: examples/qq/app.qss
================================================
================================================
FILE: examples/qq/components/header/header.js
================================================
const helloStore = require('../../stores/helloStore')
const indexStore = require('../../stores/indexStore')
const globalStore = require('../../stores/globalStore')
Component({
lifetimes: {
ready() {
helloStore.bind(this, '$hello');
indexStore.bind(this, '$index');
globalStore.bind(this, '$data');
},
detached() {
helloStore.unbind(this)
indexStore.unbind(this)
globalStore.unbind(this)
},
},
methods: {
handleChangeLang() {
globalStore.onChangeLang()
},
},
});
================================================
FILE: examples/qq/components/header/header.json
================================================
{
"component": true
}
================================================
FILE: examples/qq/components/header/header.qml
================================================
<view class="comm-header">
<view style="margin: 20rpx; font-size: 38rpx; color: blue">
Hello页标题:{{$hello.title}}
</view>
<view style="margin: 20rpx; font-size: 38rpx; color: blue">
index页标题:{{$index.title}}
</view>
<view>
<view>{{$data.description}}</view>
</view>
<view style="margin: 20rpx">
<view style="color: blue">当前语言:{{$data.language==='zh_cn'?'中文':'英文'}}</view>
<button type="primary" size="mini" bindtap="handleChangeLang">切换语言</button>
</view>
</view>
================================================
FILE: examples/qq/components/header/header.qss
================================================
.comm-header {
padding: 30rpx 0;
background-color: lightgreen;
font-weight: bold;
font-size: 30rpx;
line-height: 1.5;
color: #333;
text-align: center;
}
================================================
FILE: examples/qq/package.json
================================================
{
"name": "demo",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"mini-stores": "^1.0.0"
}
}
================================================
FILE: examples/qq/pages/hello/hello.js
================================================
const helloStore = require('../../stores/helloStore')
const globalStore = require('../../stores/globalStore')
Page({
data: {},
onLoad() {
helloStore.bind(this, '$hello');
globalStore.bind(this, '$data');
globalStore.watch.on('language', console.log, this)
},
onUnload() {
helloStore.unbind(this)
globalStore.unbind(this)
},
handleChangeTitle() {
helloStore.onChangeTitle()
},
goBack() {
qq.navigateBack()
}
});
================================================
FILE: examples/qq/pages/hello/hello.json
================================================
{
"usingComponents":{
"header":"/components/header/header"
}
}
================================================
FILE: examples/qq/pages/hello/hello.qml
================================================
<view class="hello">
<header />
<view>
<button type="primary" style="margin: auto; width: 300rpx" bindtap="handleChangeTitle">更改标题</button>
</view>
<view class="hello-title">{{$hello.title}}</view>
<view class="hello-footer">
<button type="primary" bindtap="goBack">返回上一页</button>
</view>
</view>
================================================
FILE: examples/qq/pages/hello/hello.qss
================================================
.hello {
height: 100vh;
display: flex;
flex-direction: column;
justify-content: space-between;
}
.hello-title {
font-size: 80rpx;
font-weight: bolder;
text-align: center
}
================================================
FILE: examples/qq/pages/index/index.js
================================================
const indexStore = require('../../stores/indexStore')
const globalStore = require('../../stores/globalStore')
Page({
data: {
privateData: '私有状态'
},
onLoad() {
indexStore.bind(this, '$index');
globalStore.bind(this, '$data');
globalStore.watch.on('language', console.log, this)
},
handleChangeTitle() {
indexStore.data.title = '首页' + Math.floor(Math.random() * 1000)
},
goPage() {
qq.navigateTo({ url: '/pages/hello/hello' })
}
});
================================================
FILE: examples/qq/pages/index/index.json
================================================
{
"usingComponents":{
"header":"/components/header/header"
}
}
================================================
FILE: examples/qq/pages/index/index.qml
================================================
<view class="index">
<header />
<view class="index-title">{{$index.title}}</view>
<view>{{$index.a.b.c}}</view>
<view>
<button type="primary" style="margin: auto; width: 300rpx" bindtap="handleChangeTitle">更改标题</button>
</view>
<view class="index-footer">
<button type="primary" bindtap="goPage">下一个页面</button>
</view>
</view>
================================================
FILE: examples/qq/pages/index/index.qss
================================================
.index {
height: 100vh;
display: flex;
flex-direction: column;
justify-content: space-between;
text-align: center;
}
.index-title {
font-size: 80rpx;
font-weight: bolder;
text-align: center
}
================================================
FILE: examples/qq/project.config.json
================================================
{
"description": "项目配置文件",
"packOptions": {
"ignore": []
},
"setting": {
"bundle": false,
"userConfirmedBundleSwitch": false,
"urlCheck": true,
"scopeDataCheck": false,
"coverView": true,
"es6": true,
"postcss": true,
"compileHotReLoad": false,
"lazyloadPlaceholderEnable": false,
"preloadBackgroundData": false,
"minified": true,
"autoAudits": false,
"newFeature": false,
"uglifyFileName": false,
"uploadWithSourceMap": true,
"useIsolateContext": true,
"nodeModules": false,
"enhance": true,
"useMultiFrameRuntime": true,
"useApiHook": true,
"useApiHostProcess": true,
"showShadowRootInWxmlPanel": true,
"packNpmManually": false,
"enableEngineNative": false,
"packNpmRelationList": [],
"minifyWXSS": true,
"showES6CompileOption": false,
"remoteDebugLogEnable": false,
"prefetch": false
},
"compileType": "miniprogram",
"libVersion": "2.17.0",
"appid": "wx84727eb836a04125",
"projectname": "miniprogram-1",
"debugOptions": {
"hidedInDevtools": []
},
"scripts": {},
"staticServerOptions": {
"baseURL": "",
"servePath": ""
},
"isGameTourist": false,
"qqappid": "1108100302",
"condition": {
"search": {
"list": []
},
"conversation": {
"list": []
},
"game": {
"list": []
},
"plugin": {
"list": []
},
"gamePlugin": {
"list": []
},
"miniprogram": {
"list": []
}
}
}
================================================
FILE: examples/qq/sitemap.json
================================================
{
"desc": "关于本文件的更多信息,请参考文档 https://developers.weixin.qq.com/miniprogram/dev/framework/sitemap.html",
"rules": [{
"action": "allow",
"page": "*"
}]
}
================================================
FILE: examples/qq/stores/globalStore.js
================================================
// 全局store
const create = require('mini-stores')
class Store extends create.Store {
data = {
language: "zh_cn",
userName: '李狗蛋',
corpName: '富土康化肥厂',
// 函数属性
description() {
return `我是${this.userName},我在${this.corpName}工作`
},
a: {
b: {
// 深层嵌套函数属性
c() {
return this.language + this.description
}
}
}
}
onChangeLang() {
if(this.data.language === 'zh_cn') {
this.data.language = 'en_US'
} else {
this.data.language = 'zh_cn'
}
}
}
module.exports = new Store();
================================================
FILE: examples/qq/stores/helloStore.js
================================================
const create = require('mini-stores')
class Store extends create.Store {
data = {
title: 'Hello页',
}
onChangeTitle() {
this.data.title = 'Hello页' + Math.floor(Math.random() * 1000)
}
}
module.exports = new Store();
================================================
FILE: examples/qq/stores/indexStore.js
================================================
const create = require('mini-stores')
class Store extends create.Store {
data = {
title: '首页',
a: {
b: {
c() {
return '嵌套节点也支持函数属性-' + this.title
}
}
}
}
}
module.exports = new Store();
================================================
FILE: examples/wx/app.js
================================================
App({
onLaunch(options) {
},
onShow(options) {
},
});
================================================
FILE: examples/wx/app.json
================================================
{
"pages": [
"pages/index/index",
"pages/hello/hello"
],
"window": {
"navigationBarTitleText": "小程序多状态管理"
},
"sitemapLocation": "sitemap.json"
}
================================================
FILE: examples/wx/app.wxss
================================================
================================================
FILE: examples/wx/components/header/header.js
================================================
const helloStore = require('../../stores/helloStore')
const indexStore = require('../../stores/indexStore')
const globalStore = require('../../stores/globalStore')
Component({
lifetimes: {
ready() {
helloStore.bind(this, '$hello');
indexStore.bind(this, '$index');
globalStore.bind(this, '$data');
},
detached() {
helloStore.unbind(this)
indexStore.unbind(this)
globalStore.unbind(this)
},
},
methods: {
handleChangeLang() {
globalStore.onChangeLang()
},
},
});
================================================
FILE: examples/wx/components/header/header.json
================================================
{
"component": true
}
================================================
FILE: examples/wx/components/header/header.wxml
================================================
<view class="comm-header">
<view style="margin: 20rpx; font-size: 38rpx; color: blue">
Hello页标题:{{$hello.title}}
</view>
<view style="margin: 20rpx; font-size: 38rpx; color: blue">
index页标题:{{$index.title}}
</view>
<view>
<view>{{$data.description}}</view>
</view>
<view style="margin: 20rpx">
<view style="color: blue">当前语言:{{$data.language==='zh_cn'?'中文':'英文'}}</view>
<button type="primary" size="mini" bindtap="handleChangeLang">切换语言</button>
</view>
</view>
================================================
FILE: examples/wx/components/header/header.wxss
================================================
.comm-header {
padding: 30rpx 0;
background-color: lightgreen;
font-weight: bold;
font-size: 30rpx;
line-height: 1.5;
color: #333;
text-align: center;
}
================================================
FILE: examples/wx/package.json
================================================
{
"name": "demo",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"mini-stores": "^1.1.1"
}
}
================================================
FILE: examples/wx/pages/hello/hello.js
================================================
const helloStore = require('../../stores/helloStore')
const globalStore = require('../../stores/globalStore')
Page({
data: {},
onLoad() {
helloStore.bind(this, '$hello');
globalStore.bind(this, '$data');
globalStore.watch.on('language', console.log, this)
},
onUnload() {
helloStore.unbind(this)
globalStore.unbind(this)
},
handleChangeTitle() {
helloStore.onChangeTitle()
},
goBack() {
wx.navigateBack()
}
});
================================================
FILE: examples/wx/pages/hello/hello.json
================================================
{
"usingComponents":{
"header":"/components/header/header"
}
}
================================================
FILE: examples/wx/pages/hello/hello.wxml
================================================
<view class="hello">
<header />
<view>
<button type="primary" style="margin: auto; width: 300rpx" bindtap="handleChangeTitle">更改标题</button>
</view>
<view class="hello-title">{{$hello.title}}</view>
<view class="hello-footer">
<button type="primary" bindtap="goBack">返回上一页</button>
</view>
</view>
================================================
FILE: examples/wx/pages/hello/hello.wxss
================================================
.hello {
height: 100vh;
display: flex;
flex-direction: column;
justify-content: space-between;
}
.hello-title {
font-size: 80rpx;
font-weight: bolder;
text-align: center
}
================================================
FILE: examples/wx/pages/index/index.js
================================================
const indexStore = require('../../stores/indexStore')
const globalStore = require('../../stores/globalStore');
Page({
data: {
privateData: '私有状态'
},
onLoad() {
indexStore.bind(this, '$index');
globalStore.bind(this, '$data');
globalStore.watch.on('language', console.log, this)
},
onUnload() {
indexStore.unbind(this)
globalStore.unbind(this)
},
handleChangeTitle() {
indexStore.data.title = '首页' + Math.floor(Math.random() * 1000)
},
goPage() {
wx.navigateTo({ url: '/pages/hello/hello' })
}
});
================================================
FILE: examples/wx/pages/index/index.json
================================================
{
"usingComponents":{
"header":"/components/header/header"
}
}
================================================
FILE: examples/wx/pages/index/index.wxml
================================================
<view class="index">
<header />
<view class="index-title">{{$index.title}}</view>
<view>{{$index.a.b.c}}</view>
<view>
<button type="primary" style="margin: auto; width: 300rpx" bindtap="handleChangeTitle">更改标题</button>
</view>
<view class="index-footer">
<button type="primary" bindtap="goPage">下一个页面</button>
</view>
</view>
================================================
FILE: examples/wx/pages/index/index.wxss
================================================
.index {
height: 100vh;
display: flex;
flex-direction: column;
justify-content: space-between;
text-align: center;
}
.index-title {
font-size: 80rpx;
font-weight: bolder;
text-align: center
}
================================================
FILE: examples/wx/project.config.json
================================================
{
"description": "项目配置文件",
"packOptions": {
"ignore": [],
"include": []
},
"setting": {
"bundle": false,
"userConfirmedBundleSwitch": false,
"urlCheck": true,
"scopeDataCheck": false,
"coverView": true,
"es6": true,
"postcss": true,
"compileHotReLoad": false,
"lazyloadPlaceholderEnable": false,
"preloadBackgroundData": false,
"minified": true,
"autoAudits": false,
"newFeature": false,
"uglifyFileName": false,
"uploadWithSourceMap": true,
"useIsolateContext": true,
"nodeModules": false,
"enhance": true,
"useMultiFrameRuntime": true,
"useApiHook": true,
"useApiHostProcess": true,
"showShadowRootInWxmlPanel": true,
"packNpmManually": false,
"enableEngineNative": false,
"packNpmRelationList": [],
"minifyWXSS": true,
"showES6CompileOption": false,
"babelSetting": {
"ignore": [],
"disablePlugins": [],
"outputPath": ""
},
"condition": false,
"ignoreUploadUnusedFiles": true
},
"compileType": "miniprogram",
"libVersion": "3.9.2",
"appid": "wx84727eb836a04125",
"projectname": "miniprogram-1",
"condition": {},
"editorSetting": {
"tabIndent": "insertSpaces",
"tabSize": 2
}
}
================================================
FILE: examples/wx/sitemap.json
================================================
{
"desc": "关于本文件的更多信息,请参考文档 https://developers.weixin.qq.com/miniprogram/dev/framework/sitemap.html",
"rules": [{
"action": "allow",
"page": "*"
}]
}
================================================
FILE: examples/wx/stores/globalStore.js
================================================
// 全局store
const create = require('mini-stores')
class Store extends create.Store {
data = {
language: "zh_cn",
userName: '李狗蛋',
corpName: '富土康化肥厂',
// 函数属性
description() {
return `我是${this.userName},我在${this.corpName}工作`
},
a: {
b: {
// 深层嵌套函数属性
c() {
return this.language + this.description
}
}
}
}
onChangeLang() {
if(this.data.language === 'zh_cn') {
this.data.language = 'en_US'
} else {
this.data.language = 'zh_cn'
}
}
}
module.exports = new Store();
================================================
FILE: examples/wx/stores/helloStore.js
================================================
const create = require('mini-stores')
class Store extends create.Store {
data = {
title: 'Hello页',
}
onChangeTitle() {
this.data.title = 'Hello页' + Math.floor(Math.random() * 1000)
}
}
module.exports = new Store();
================================================
FILE: examples/wx/stores/indexStore.js
================================================
const create = require('mini-stores')
class Store extends create.Store {
data = {
title: '首页',
a: {
b: {
c() {
return '嵌套节点也支持函数属性-' + this.title
}
}
}
}
}
module.exports = new Store();
================================================
FILE: package.json
================================================
{
"name": "mini-stores",
"version": "2.3.0",
"description": "小程序多状态管理 - 解决跨页面跨组件间通信,简洁小巧高性能,支持微信、支付宝、钉钉、百度、字节、QQ等小程序",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"module": "dist/index.js",
"files": [
"dist",
"readme.md"
],
"scripts": {
"build": "yarn build:types && yarn build:js",
"build:js": "babel src -d dist -x .ts,.js",
"build:types": "tsc",
"watch": "babel src -w -d dist -x .ts,.js"
},
"author": "linjc (https://github.com/linjc)",
"keywords": [
"mini-stores",
"小程序状态管理库",
"小程序全局多状态管理",
"小程序跨页面组件通信",
"微信小程序状态管理",
"钉钉小程序状态管理",
"支付宝小程序状态管理",
"京东小程序状态管理",
"QQ小程序状态管理",
"百度小程序状态管理",
"字节小程序状态管理"
],
"homepage": "https://github.com/linjc/mini-stores",
"repository": {
"type": "git",
"url": "https://github.com/linjc/mini-stores.git"
},
"bugs": {
"url": "https://github.com/linjc/mini-stores/issues"
},
"license": "MIT",
"devDependencies": {
"@babel/cli": "^7.27.1",
"@babel/core": "^7.27.1",
"@babel/preset-env": "^7.27.1",
"@babel/preset-typescript": "^7.27.1",
"babel-preset-env": "^1.7.0",
"miniprogram-api-typings": "^4.0.7",
"typescript": "^5.8.3"
}
}
================================================
FILE: readme.md
================================================
# mini-stores - 小程序多状态管理
- [前言](#前言)
- [安装](#安装)
- [使用](#使用)
- [创建store](#创建store)
- [页面内使用](#页面内使用)
- [组件内使用](#组件内使用)
- [视图上使用](#视图上使用)
- [监听状态](#监听状态)
- [使用建议](#使用建议)
- [快捷链接](#快捷链接)
## 前言
小程序没有官方实现的状态管理库,用过redux、vuex、mobx等状态管理库的前端小伙伴都知道,状态管理能很轻松帮我们解决很多跨页面跨组件通信问题。一开始写了一个Emitter类,用事件监听方式去实现全局状态管理,但这种方式相对繁琐且不够直观。于是网上寻找有没有更好的解决方案,最终找到了[westore](https://github.com/Tencent/westore/tree/v1)库,这是由腾讯开源团队研发的微信小程序解决方案,其中针对状态管理的实现很不错,而且还使用专门为小程序开发的[JSON Diff 库](https://github.com/Tencent/westore/blob/v1/utils/diff.js)保证每次以最小的数据量更新状态,比原生setData的性能更好。但由于不支持同时多例store及私有状态等,于是在看了源码之后,基于其核心原理重写了一版,另外根据自身理解做了如下改进:
### 1、优化渲染效率
每次更新store状态的时候,只对当前页面进行渲染,其他后台态页面延迟更新。这样可以大大减少同时setData的频次,提高渲染效率。
### 2、支持多例store
一个页面或者组件可以同时使用多个store,且不破坏原有私有状态的定义。
### 3、简化状态触发渲染
直接更改store的状态值,即可触发组件重渲染,无需手动调用setData方法
### 4、支持多平台
支持微信/支付宝/钉钉/百度/字节/抖音/QQ/京东等小程序使用。对于其他小程序,理论上也可以直接拿来用,使用时可自行验证。
## 安装
``` js
npm i mini-stores --save
```
## 使用
#### 创建store
store继承于mini-stores提供的Store类,其中状态定义在data对象内,并支持函数计算属性(计算属性中的this指向store.data对象)
``` js
const create = require('mini-stores')
class Store extends create.Store {
data = {
title: '小程序多状态管理',
language: "zh_cn",
userName: '李狗蛋',
deptName: '化肥质检部门',
corpName: '富土康化肥厂',
// 函数属性 - 可直接绑定到视图上
description() {
return `我是${this.userName},我在${this.corpName}工作`
},
a: {
b: {
// 深层嵌套也支持函数属性
c() {
return this.language + this.description
}
}
}
}
onChangeLang() {
if(this.data.language === 'zh_cn') {
this.data.language = 'en_US'
} else {
this.data.language = 'zh_cn'
}
}
}
export default new Store()
```
#### 页面内使用
在页面的初始化时(onLoad)绑定store,页面销毁时(onUnload)解除store绑定。
store.bind方法使用:store.bind(this, '$data'), 第一个参数this为当前页面实例,第二参数为该store在视图上使用的key名。注意该key在视图上使用时,并不是对应store,而是store.data值。另外定义key名注意不要和现有的私有变量同名,个人建议可以加个前缀(如$),这样可以一眼区分它来自全局状态。
``` js
import globalStore from '/stores/globalStore'
import indexStore from '/stores/indexStore'
Page({
data: {
privateData: '私有状态' // 私有状态还是通过原有的setData更新
},
onLoad() {
// 绑定实例到store上,第二参数定义视图上使用的key名,命名随意,但注意不要和页面data内的私有变量同名
indexStore.bind(this, '$index');
globalStore.bind(this, '$data');
},
// 页面销毁时解除绑定
onUnload() {
indexStore.unbind(this)
globalStore.unbind(this)
},
handleChangeTitle() {
globalStore.data.title = '新标题'
},
handleChangeName() {
indexStore.changeName()
}
});
```
#### 组件内使用
和页面内使用一样,在组件初始化时进行store绑定,在组件销毁时解除绑定。
各平台组件生命周期函数写法可能有所区别,根据对应官方文档来写即可。
``` js
import globalStore from '/stores/globalStore'
import indexStore from '/stores/indexStore'
Component({
data: {
privateData: '私有状态'
},
// 阿里系小程序
didMount() {
indexStore.bind(this, '$index');
globalStore.bind(this, '$data');
},
didUnmount() {
// 组件销毁时解除绑定
indexStore.unbind(this)
globalStore.unbind(this)
},
// 微信小程序等大部分小程序
lifetimes: {
ready() {
indexStore.bind(this, '$index');
globalStore.bind(this, '$data');
},
detached() {
// 组件销毁时解除绑定
helloStore.unbind(this)
globalStore.unbind(this)
},
},
methods: {
handleChangeTitle() {
globalStore.data.title = '新标题'
},
handleChangeName() {
indexStore.changeName()
}
}
});
```
#### 视图上使用
简单示例:
``` js
<view>
<view>{{$index.title}}</view>
<view>{{$data.language}}</view>
<view>{{$data.description}}</view>
<view>{{$index.a.b.c}}</view>
<view>{{privateData}}<view>
</view>
```
#### 监听状态
添加监听:store.watch.on('key', fn)
移除监听:store.watch.off('key', fn)
key支持简单的对象点路径写法,从而实现监听深层字段,如:'a.b.c.d'
``` js
import globalStore from '/stores/globalStore'
Page({
onLoad() {
globalStore.bind(this, '$data');
// 添加监听
globalStore.watch.on('language', this.onWatchLang)
},
onUnload() {
globalStore.unbind(this)
// 移除监听,避免内存泄露
globalStore.watch.off('language', this.onWatchLang)
},
onWatchLang(value, oldValue) {
console.log('language change:', value, oldValue)
},
});
```
如果觉得每次写移除监听很繁琐,可以在添加监听时传入组件实例(第三个参数),所有当前实例下的监听事件会在store.unbind时自动移除,参考如下:
``` js
import globalStore from '/stores/globalStore'
Page({
onLoad() {
// 添加监听,第三个参数传入当前实例
globalStore.watch.on('language', this.onWatchLang, this)
},
onUnload() {
globalStore.unbind(this)
},
onWatchLang(value, oldValue) {
console.log('language change:', value, oldValue)
},
});
```
## 使用建议
1、不一定非要使用全局状态管理,涉及到跨页面组件通信时,再考虑使用也可,mini-stores对小程序代码零破坏性,可随时加入或去掉。
2、使用时,建议将状态和逻辑提取到store上,页面只负责处理用户事件的监听和回调,这样的好处是:
* 保持页面代码简洁,可以快速对页面的用户事件一目了然,更好把控业务。
* 状态逻辑在独立的js上,方便实现逻辑复用,且更易于代码测试,对使用函数式编程非常友好。
使用过程中有什么问题或建议可以在**Issues**进行反馈
## 快捷链接
- [Example示例](./examples)
- [Github仓库](https://github.com/linjc/mini-stores)
- [Gitee仓库](https://gitee.com/l2j2c3/mini-stores)
================================================
FILE: src/index.ts
================================================
const TYPE_ARRAY = '[object Array]';
const TYPE_OBJECT = '[object Object]';
const TYPE_FUNCTION = '[object Function]';
type PlainObject = Record<string, any>;
function getType(obj: any): string {
return Object.prototype.toString.call(obj);
}
function deepCopy(data: any): any {
const type = getType(data);
if (type === TYPE_OBJECT) {
const obj: PlainObject = {};
Object.keys(data).forEach(key => obj[key] = deepCopy(data[key]));
return obj;
}
if (type === TYPE_ARRAY) {
return (data as any[]).map(deepCopy);
}
return data;
}
function getNowPage(): any {
const pages = getCurrentPages();
return pages[pages.length - 1];
}
function setState(vm: any, data: PlainObject): Promise<void> {
vm._new_data = vm._new_data || {};
Object.assign(vm._new_data, data);
return new Promise(resolve => {
Promise.resolve().then(() => {
if (vm._new_data) {
const diffState = getDiffState(vm._new_data, vm.data);
vm._new_data = null;
vm.setData(diffState, resolve);
} else {
resolve();
}
});
});
}
function getDiffState(state: any, preState: any): PlainObject {
const newState: PlainObject = {};
stateDiff(deepCopy(state), preState, '', newState);
return newState;
}
function addDiffState(newState: PlainObject, key: string, val: any): void {
if (key !== '') newState[key] = val;
}
function stateDiff(state: any, preState: any, path: string, newState: PlainObject): void {
if (state === preState) return;
const stateType = getType(state);
const preStateType = getType(preState);
if (stateType === TYPE_OBJECT) {
const stateKeys = Object.keys(state);
const preStateKeys = Object.keys(preState || {});
const stateLen = stateKeys.length;
const preStateLen = preStateKeys.length;
if (path !== '') {
if (preStateType !== TYPE_OBJECT || stateLen < preStateLen || stateLen === 0 || preStateLen === 0) {
addDiffState(newState, path, state);
return;
}
preStateKeys.forEach(key => {
if (state[key] === undefined) {
state[key] = null;
if (!stateKeys.includes(key)) {
stateKeys.push(key);
}
}
});
}
stateKeys.forEach(key => {
const subPath = path === '' ? key : `${path}.${key}`;
stateDiff(state[key], preState[key], subPath, newState);
});
return;
}
if (stateType === TYPE_ARRAY) {
if (preStateType !== TYPE_ARRAY || state.length < preState.length || state.length === 0 || preState.length === 0) {
addDiffState(newState, path, state);
return;
}
preState.forEach((_: any, index: number) => {
if (state[index] === undefined) state[index] = null;
});
state.forEach((item: any, index: number) => {
stateDiff(item, preState[index], `${path}[${index}]`, newState);
});
return;
}
addDiffState(newState, path, state);
}
function getVmRoute(vm: any): string {
return vm.route;
}
function initRoute(vm: any): string {
return vm.route || vm.__route__;
}
interface BoundVM {
vm: any;
key: string;
}
type WatchCallback = (value: any, oldValue: any) => void
interface WatchItem {
value: any,
paths: string[],
callbacks: {
vm?: any,
callback: WatchCallback,
}[]
}
function getValueByPaths(data: any, paths: string[]) {
let value = data
paths.forEach(key => {
value = value?.[key]
})
return value
}
export class Store {
private __vms: BoundVM[] = [];
private __delayTimer: ReturnType<typeof setTimeout> | null = null;
private __updateTimer: any = null;
private __watchTimer: any = null;
private __watchMap: Record<string, WatchItem> = {}
public data: PlainObject = {};
public watch = {
on: (key: string, callback: WatchCallback, vm?: any) => {
if (!key || typeof callback !== 'function') {
console.warn(`请传入正确参数,如store.watch.on('key', () => {})`)
return
}
key = String(key)
if (!this.__watchMap[key]) {
const paths = String(key).split('.').filter(f => !!f)
if (!paths.length) return
this.__watchMap[key] = {
paths,
value: getValueByPaths(this.data, paths),
callbacks: []
}
}
this.__watchMap[key].callbacks.push({ vm, callback })
},
off: (key: string, callback: WatchCallback) => {
key = String(key)
if (!this.__watchMap[key]) return
this.__watchMap[key].callbacks = this.__watchMap[key].callbacks.filter(f => f.callback !== callback)
}
}
constructor() {
setTimeout(() => {
this.data = this.__createProxy(this.data);
}, 0)
}
private __proxyCache = new WeakMap()
private __createProxy = (obj: Record<string, any>) => {
if (this.__proxyCache.has(obj)) {
return this.__proxyCache.get(obj)
}
const proxy = new Proxy(obj, {
get: (target, propKey, receiver) => {
const value = Reflect.get(target, propKey, receiver);
const type = getType(value)
if (type === TYPE_FUNCTION) {
return value.call(this.data)
}
if (type === TYPE_OBJECT) {
return this.__createProxy(value)
}
return value
},
set: (target, propKey, value, receiver) => {
clearTimeout(this.__updateTimer)
this.__updateTimer = setTimeout(() => this.__update())
return Reflect.set(target, propKey, value, receiver);
},
})
this.__proxyCache.set(obj, proxy)
return proxy
}
public bind(vm: any, key: string): void {
if (!key) {
console.error(`请设置store在当前组件实例data中的key,如store.bind(this, '$store')`);
return;
}
vm.data = vm.data || {};
vm.data[key] = null;
setState(vm, { [key]: this.data });
if (!this.__vms.some(f => f.vm === vm && f.key === key)) {
this.__vms.push({ vm, key });
const rootVm = vm.$page || vm.pageinstance || getNowPage() || {};
vm.route = initRoute(vm) || initRoute(rootVm);
}
}
public unbind(vm: any): void {
this.__vms = this.__vms.filter(f => f.vm !== vm);
Object.keys(this.__watchMap).forEach(key => {
this.__watchMap[key].callbacks = this.__watchMap[key].callbacks.filter(f => f.vm !== vm)
})
}
private __update(): void {
const nowVm = getNowPage();
const nowVmRoute = getVmRoute(nowVm)
const delayVms: BoundVM[] = [];
this.__vms.forEach(f => {
const vmRoute = getVmRoute(f.vm);
if (nowVmRoute === vmRoute) {
setState(f.vm, { [f.key]: this.data });
} else {
delayVms.push(f);
}
});
clearTimeout(this.__watchTimer)
this.__watchTimer = setTimeout(() => {
Object.keys(this.__watchMap).forEach(key => {
const item = this.__watchMap[key]
const value = getValueByPaths(this.data, item.paths)
const oldValue = item.value
if (oldValue !== value) {
item.value = value
item.callbacks.forEach(f => f.callback(value, oldValue))
}
})
}, 0)
if (!delayVms.length) return;
clearTimeout(this.__delayTimer as ReturnType<typeof setTimeout>);
this.__delayTimer = setTimeout(() => {
delayVms.forEach(f => setState(f.vm, { [f.key]: this.data }));
}, 360);
}
public update(): void {
this.__update()
}
}
================================================
FILE: tsconfig.json
================================================
{
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"declaration": true,
"emitDeclarationOnly": true,
"outDir": "./dist",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true,
"types": [
"miniprogram-api-typings"
]
},
"include": [
"src"
]
}
gitextract_46bjt__b/ ├── .gitignore ├── .npmignore ├── LICENSE ├── babel.config.json ├── examples/ │ ├── alipay/ │ │ ├── app.acss │ │ ├── app.js │ │ ├── app.json │ │ ├── components/ │ │ │ └── header/ │ │ │ ├── header.acss │ │ │ ├── header.axml │ │ │ ├── header.js │ │ │ └── header.json │ │ ├── package.json │ │ ├── pages/ │ │ │ ├── hello/ │ │ │ │ ├── hello.acss │ │ │ │ ├── hello.axml │ │ │ │ ├── hello.js │ │ │ │ └── hello.json │ │ │ └── index/ │ │ │ ├── index.acss │ │ │ ├── index.axml │ │ │ ├── index.js │ │ │ └── index.json │ │ └── stores/ │ │ ├── globalStore.js │ │ ├── helloStore.js │ │ └── indexStore.js │ ├── baidu/ │ │ ├── app.css │ │ ├── app.js │ │ ├── app.json │ │ ├── components/ │ │ │ └── header/ │ │ │ ├── header.css │ │ │ ├── header.js │ │ │ ├── header.json │ │ │ └── header.swan │ │ ├── package.json │ │ ├── pages/ │ │ │ ├── hello/ │ │ │ │ ├── hello.css │ │ │ │ ├── hello.js │ │ │ │ ├── hello.json │ │ │ │ └── hello.swan │ │ │ └── index/ │ │ │ ├── index.css │ │ │ ├── index.js │ │ │ ├── index.json │ │ │ └── index.swan │ │ ├── project.swan.json │ │ └── stores/ │ │ ├── globalStore.js │ │ ├── helloStore.js │ │ └── indexStore.js │ ├── bytedance/ │ │ ├── app.js │ │ ├── app.json │ │ ├── app.ttss │ │ ├── components/ │ │ │ └── header/ │ │ │ ├── header.js │ │ │ ├── header.json │ │ │ ├── header.ttml │ │ │ └── header.ttss │ │ ├── package.json │ │ ├── pages/ │ │ │ ├── hello/ │ │ │ │ ├── hello.js │ │ │ │ ├── hello.json │ │ │ │ ├── hello.ttml │ │ │ │ └── hello.ttss │ │ │ └── index/ │ │ │ ├── index.js │ │ │ ├── index.json │ │ │ ├── index.ttml │ │ │ └── index.ttss │ │ ├── project.config.json │ │ ├── sitemap.json │ │ └── stores/ │ │ ├── globalStore.js │ │ ├── helloStore.js │ │ └── indexStore.js │ ├── dd/ │ │ ├── app.acss │ │ ├── app.js │ │ ├── app.json │ │ ├── components/ │ │ │ └── header/ │ │ │ ├── header.acss │ │ │ ├── header.axml │ │ │ ├── header.js │ │ │ └── header.json │ │ ├── package.json │ │ ├── pages/ │ │ │ ├── hello/ │ │ │ │ ├── hello.acss │ │ │ │ ├── hello.axml │ │ │ │ ├── hello.js │ │ │ │ └── hello.json │ │ │ └── index/ │ │ │ ├── index.acss │ │ │ ├── index.axml │ │ │ ├── index.js │ │ │ └── index.json │ │ └── stores/ │ │ ├── globalStore.js │ │ ├── helloStore.js │ │ └── indexStore.js │ ├── jd/ │ │ ├── app.js │ │ ├── app.json │ │ ├── app.jxss │ │ ├── components/ │ │ │ └── header/ │ │ │ ├── header.js │ │ │ ├── header.json │ │ │ ├── header.jxml │ │ │ └── header.jxss │ │ ├── package.json │ │ ├── pages/ │ │ │ ├── hello/ │ │ │ │ ├── hello.js │ │ │ │ ├── hello.json │ │ │ │ ├── hello.jxml │ │ │ │ └── hello.jxss │ │ │ └── index/ │ │ │ ├── index.js │ │ │ ├── index.json │ │ │ ├── index.jxml │ │ │ └── index.jxss │ │ ├── project.config.json │ │ ├── sitemap.json │ │ └── stores/ │ │ ├── globalStore.js │ │ ├── helloStore.js │ │ └── indexStore.js │ ├── qq/ │ │ ├── app.js │ │ ├── app.json │ │ ├── app.qss │ │ ├── components/ │ │ │ └── header/ │ │ │ ├── header.js │ │ │ ├── header.json │ │ │ ├── header.qml │ │ │ └── header.qss │ │ ├── package.json │ │ ├── pages/ │ │ │ ├── hello/ │ │ │ │ ├── hello.js │ │ │ │ ├── hello.json │ │ │ │ ├── hello.qml │ │ │ │ └── hello.qss │ │ │ └── index/ │ │ │ ├── index.js │ │ │ ├── index.json │ │ │ ├── index.qml │ │ │ └── index.qss │ │ ├── project.config.json │ │ ├── sitemap.json │ │ └── stores/ │ │ ├── globalStore.js │ │ ├── helloStore.js │ │ └── indexStore.js │ └── wx/ │ ├── app.js │ ├── app.json │ ├── app.wxss │ ├── components/ │ │ └── header/ │ │ ├── header.js │ │ ├── header.json │ │ ├── header.wxml │ │ └── header.wxss │ ├── package.json │ ├── pages/ │ │ ├── hello/ │ │ │ ├── hello.js │ │ │ ├── hello.json │ │ │ ├── hello.wxml │ │ │ └── hello.wxss │ │ └── index/ │ │ ├── index.js │ │ ├── index.json │ │ ├── index.wxml │ │ └── index.wxss │ ├── project.config.json │ ├── sitemap.json │ └── stores/ │ ├── globalStore.js │ ├── helloStore.js │ └── indexStore.js ├── package.json ├── readme.md ├── src/ │ └── index.ts └── tsconfig.json
SYMBOL INDEX (164 symbols across 49 files)
FILE: examples/alipay/app.js
method onLaunch (line 3) | onLaunch(options) {
method onShow (line 7) | onShow(options) {
FILE: examples/alipay/components/header/header.js
method didMount (line 8) | didMount() {
method didUnmount (line 14) | didUnmount() {
method handleChangeLang (line 21) | handleChangeLang() {
FILE: examples/alipay/pages/hello/hello.js
method onLoad (line 8) | onLoad() {
method onUnload (line 14) | onUnload() {
method handleChangeTitle (line 19) | handleChangeTitle() {
method goBack (line 23) | goBack() {
FILE: examples/alipay/pages/index/index.js
method onLoad (line 10) | onLoad() {
method onUnload (line 16) | onUnload() {
method handleChangeTitle (line 21) | handleChangeTitle() {
method goPage (line 25) | goPage() {
FILE: examples/alipay/stores/globalStore.js
class Store (line 4) | class Store extends create.Store {
method description (line 11) | description() {
method c (line 17) | c() {
method onChangeLang (line 24) | onChangeLang() {
FILE: examples/alipay/stores/helloStore.js
class Store (line 3) | class Store extends create.Store {
method onChangeTitle (line 9) | onChangeTitle() {
FILE: examples/alipay/stores/indexStore.js
class Store (line 3) | class Store extends create.Store {
method c (line 9) | c() {
FILE: examples/baidu/components/header/header.js
method ready (line 7) | ready() {
method detached (line 13) | detached() {
method handleChangeLang (line 21) | handleChangeLang() {
FILE: examples/baidu/pages/hello/hello.js
method onLoad (line 10) | onLoad() {
method onUnload (line 16) | onUnload() {
method handleChangeTitle (line 21) | handleChangeTitle() {
method goBack (line 25) | goBack() {
FILE: examples/baidu/pages/index/index.js
method onLoad (line 10) | onLoad() {
method onUnload (line 16) | onUnload() {
method handleChangeTitle (line 21) | handleChangeTitle() {
method goPage (line 25) | goPage() {
FILE: examples/baidu/stores/globalStore.js
class Store (line 4) | class Store extends create.Store {
method description (line 11) | description() {
method c (line 17) | c() {
method onChangeLang (line 24) | onChangeLang() {
FILE: examples/baidu/stores/helloStore.js
class Store (line 3) | class Store extends create.Store {
method onChangeTitle (line 9) | onChangeTitle() {
FILE: examples/baidu/stores/indexStore.js
class Store (line 3) | class Store extends create.Store {
method c (line 8) | c() {
FILE: examples/bytedance/app.js
method onLaunch (line 3) | onLaunch(options) {
method onShow (line 7) | onShow(options) {
FILE: examples/bytedance/components/header/header.js
method ready (line 8) | ready() {
method detached (line 13) | detached() {
method handleChangeLang (line 21) | handleChangeLang() {
FILE: examples/bytedance/pages/hello/hello.js
method onLoad (line 8) | onLoad() {
method onUnload (line 14) | onUnload() {
method handleChangeTitle (line 19) | handleChangeTitle() {
method goBack (line 23) | goBack() {
FILE: examples/bytedance/pages/index/index.js
method onLoad (line 10) | onLoad() {
method handleChangeTitle (line 16) | handleChangeTitle() {
method goPage (line 20) | goPage() {
FILE: examples/bytedance/stores/globalStore.js
class Store (line 4) | class Store extends create.Store {
method description (line 11) | description() {
method c (line 17) | c() {
method onChangeLang (line 24) | onChangeLang() {
FILE: examples/bytedance/stores/helloStore.js
class Store (line 4) | class Store extends create.Store {
method onChangeTitle (line 10) | onChangeTitle() {
FILE: examples/bytedance/stores/indexStore.js
class Store (line 4) | class Store extends create.Store {
method c (line 10) | c() {
FILE: examples/dd/app.js
method onLaunch (line 3) | onLaunch(options) {
method onShow (line 7) | onShow(options) {
FILE: examples/dd/components/header/header.js
method didMount (line 6) | didMount() {
method didUnmount (line 11) | didUnmount() {
method handleChangeLang (line 17) | handleChangeLang() {
FILE: examples/dd/pages/hello/hello.js
method onLoad (line 8) | onLoad() {
method onUnload (line 14) | onUnload() {
method handleChangeTitle (line 19) | handleChangeTitle() {
method goBack (line 23) | goBack() {
FILE: examples/dd/pages/index/index.js
method onLoad (line 10) | onLoad() {
method handleChangeTitle (line 16) | handleChangeTitle() {
method goPage (line 20) | goPage() {
FILE: examples/dd/stores/globalStore.js
class Store (line 4) | class Store extends create.Store {
method description (line 11) | description() {
method c (line 17) | c() {
method onChangeLang (line 24) | onChangeLang() {
FILE: examples/dd/stores/helloStore.js
class Store (line 4) | class Store extends create.Store {
method onChangeTitle (line 10) | onChangeTitle() {
FILE: examples/dd/stores/indexStore.js
class Store (line 4) | class Store extends create.Store {
method c (line 10) | c() {
FILE: examples/jd/app.js
method onLaunch (line 3) | onLaunch(options) {
method onShow (line 7) | onShow(options) {
FILE: examples/jd/components/header/header.js
method ready (line 7) | ready() {
method detached (line 13) | detached() {
method handleChangeLang (line 20) | handleChangeLang() {
FILE: examples/jd/pages/hello/hello.js
method onLoad (line 8) | onLoad() {
method onUnload (line 14) | onUnload() {
method handleChangeTitle (line 19) | handleChangeTitle() {
method goBack (line 23) | goBack() {
FILE: examples/jd/pages/index/index.js
method onLoad (line 10) | onLoad() {
method handleChangeTitle (line 16) | handleChangeTitle() {
method goPage (line 21) | goPage() {
FILE: examples/jd/stores/globalStore.js
class Store (line 4) | class Store extends create.Store {
method description (line 11) | description() {
method c (line 17) | c() {
method onChangeLang (line 24) | onChangeLang() {
FILE: examples/jd/stores/helloStore.js
class Store (line 4) | class Store extends create.Store {
method onChangeTitle (line 10) | onChangeTitle() {
FILE: examples/jd/stores/indexStore.js
class Store (line 4) | class Store extends create.Store {
method c (line 10) | c() {
FILE: examples/qq/app.js
method onLaunch (line 3) | onLaunch(options) {
method onShow (line 7) | onShow(options) {
FILE: examples/qq/components/header/header.js
method ready (line 7) | ready() {
method detached (line 12) | detached() {
method handleChangeLang (line 19) | handleChangeLang() {
FILE: examples/qq/pages/hello/hello.js
method onLoad (line 8) | onLoad() {
method onUnload (line 14) | onUnload() {
method handleChangeTitle (line 19) | handleChangeTitle() {
method goBack (line 23) | goBack() {
FILE: examples/qq/pages/index/index.js
method onLoad (line 10) | onLoad() {
method handleChangeTitle (line 16) | handleChangeTitle() {
method goPage (line 20) | goPage() {
FILE: examples/qq/stores/globalStore.js
class Store (line 4) | class Store extends create.Store {
method description (line 11) | description() {
method c (line 17) | c() {
method onChangeLang (line 24) | onChangeLang() {
FILE: examples/qq/stores/helloStore.js
class Store (line 3) | class Store extends create.Store {
method onChangeTitle (line 9) | onChangeTitle() {
FILE: examples/qq/stores/indexStore.js
class Store (line 3) | class Store extends create.Store {
method c (line 9) | c() {
FILE: examples/wx/app.js
method onLaunch (line 3) | onLaunch(options) {
method onShow (line 7) | onShow(options) {
FILE: examples/wx/components/header/header.js
method ready (line 7) | ready() {
method detached (line 12) | detached() {
method handleChangeLang (line 20) | handleChangeLang() {
FILE: examples/wx/pages/hello/hello.js
method onLoad (line 7) | onLoad() {
method onUnload (line 13) | onUnload() {
method handleChangeTitle (line 18) | handleChangeTitle() {
method goBack (line 22) | goBack() {
FILE: examples/wx/pages/index/index.js
method onLoad (line 10) | onLoad() {
method onUnload (line 16) | onUnload() {
method handleChangeTitle (line 21) | handleChangeTitle() {
method goPage (line 25) | goPage() {
FILE: examples/wx/stores/globalStore.js
class Store (line 4) | class Store extends create.Store {
method description (line 11) | description() {
method c (line 17) | c() {
method onChangeLang (line 24) | onChangeLang() {
FILE: examples/wx/stores/helloStore.js
class Store (line 3) | class Store extends create.Store {
method onChangeTitle (line 9) | onChangeTitle() {
FILE: examples/wx/stores/indexStore.js
class Store (line 3) | class Store extends create.Store {
method c (line 9) | c() {
FILE: src/index.ts
constant TYPE_ARRAY (line 1) | const TYPE_ARRAY = '[object Array]';
constant TYPE_OBJECT (line 2) | const TYPE_OBJECT = '[object Object]';
constant TYPE_FUNCTION (line 3) | const TYPE_FUNCTION = '[object Function]';
type PlainObject (line 5) | type PlainObject = Record<string, any>;
function getType (line 7) | function getType(obj: any): string {
function deepCopy (line 11) | function deepCopy(data: any): any {
function getNowPage (line 24) | function getNowPage(): any {
function setState (line 29) | function setState(vm: any, data: PlainObject): Promise<void> {
function getDiffState (line 45) | function getDiffState(state: any, preState: any): PlainObject {
function addDiffState (line 51) | function addDiffState(newState: PlainObject, key: string, val: any): void {
function stateDiff (line 55) | function stateDiff(state: any, preState: any, path: string, newState: Pl...
function getVmRoute (line 108) | function getVmRoute(vm: any): string {
function initRoute (line 112) | function initRoute(vm: any): string {
type BoundVM (line 116) | interface BoundVM {
type WatchCallback (line 121) | type WatchCallback = (value: any, oldValue: any) => void
type WatchItem (line 122) | interface WatchItem {
function getValueByPaths (line 131) | function getValueByPaths(data: any, paths: string[]) {
class Store (line 139) | class Store {
method constructor (line 172) | constructor() {
method bind (line 205) | public bind(vm: any, key: string): void {
method unbind (line 221) | public unbind(vm: any): void {
method __update (line 228) | private __update(): void {
method update (line 262) | public update(): void {
Condensed preview — 150 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (75K chars).
[
{
"path": ".gitignore",
"chars": 265,
"preview": "\n.DS_Store\nnode_modules\nminiprogram_npm\n.tea\n.swan\n.vscode-swan\n\n# local env files\n.env.local\n.env.*.local\n\n# Log files\n"
},
{
"path": ".npmignore",
"chars": 8,
"preview": "examples"
},
{
"path": "LICENSE",
"chars": 1063,
"preview": "MIT License\n\nCopyright (c) 2021 l2j2c3\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof "
},
{
"path": "babel.config.json",
"chars": 118,
"preview": "{\n \"presets\": [\n [\"@babel/preset-env\", {\n \"modules\": \"commonjs\"\n }],\n \"@babel/preset-typescript\"\n ]\n}\n"
},
{
"path": "examples/alipay/app.acss",
"chars": 0,
"preview": ""
},
{
"path": "examples/alipay/app.js",
"chars": 66,
"preview": "App({\n\n onLaunch(options) {\n\n },\n\n onShow(options) {\n\n },\n});\n"
},
{
"path": "examples/alipay/app.json",
"chars": 120,
"preview": "{\n \"pages\": [\n \"pages/index/index\",\n \"pages/hello/hello\"\n ],\n \"window\": {\n \"defaultTitle\": \"小程序多状态管理\"\n }\n}\n"
},
{
"path": "examples/alipay/components/header/header.acss",
"chars": 166,
"preview": ".comm-header {\n padding: 30rpx 0;\n background-color: lightgreen;\n font-weight: bold;\n font-size: 30rpx;\n line-heigh"
},
{
"path": "examples/alipay/components/header/header.axml",
"chars": 496,
"preview": "<view class=\"comm-header\">\n <view style=\"margin: 20rpx; font-size: 38rpx; color: blue\">\n Hello页标题:{{$hello.title}}\n "
},
{
"path": "examples/alipay/components/header/header.js",
"chars": 489,
"preview": "import helloStore from '/stores/helloStore'\nimport indexStore from '/stores/indexStore'\nimport globalStore from '/stores"
},
{
"path": "examples/alipay/components/header/header.json",
"chars": 23,
"preview": "{\n \"component\": true\n}"
},
{
"path": "examples/alipay/package.json",
"chars": 251,
"preview": "{\n \"name\": \"demo\",\n \"version\": \"1.0.0\",\n \"description\": \"\",\n \"main\": \"app.js\",\n \"scripts\": {\n \"test\": \"echo \\\"Er"
},
{
"path": "examples/alipay/pages/hello/hello.acss",
"chars": 186,
"preview": ".hello {\n height: 100vh;\n display: flex;\n flex-direction: column;\n justify-content: space-between;\n}\n\n.hello-title {"
},
{
"path": "examples/alipay/pages/hello/hello.axml",
"chars": 313,
"preview": "<view class=\"hello\">\n <header />\n <view>\n <button type=\"primary\" style=\"margin: auto; width: 300rpx\" onTap=\"handleC"
},
{
"path": "examples/alipay/pages/hello/hello.js",
"chars": 443,
"preview": "import helloStore from '/stores/helloStore'\nimport globalStore from '/stores/globalStore'\n\nPage({\n\n data: {},\n\n onLoad"
},
{
"path": "examples/alipay/pages/hello/hello.json",
"chars": 70,
"preview": "{\n \"usingComponents\":{\n \"header\":\"/components/header/header\"\n }\n}"
},
{
"path": "examples/alipay/pages/index/index.acss",
"chars": 208,
"preview": ".index {\n height: 100vh;\n display: flex;\n flex-direction: column;\n justify-content: space-between;\n text-align: cen"
},
{
"path": "examples/alipay/pages/index/index.axml",
"chars": 345,
"preview": "<view class=\"index\">\n <header />\n <view class=\"index-title\">{{$index.title}}</view>\n <view>{{$index.a.b.c}}</view>\n "
},
{
"path": "examples/alipay/pages/index/index.js",
"chars": 535,
"preview": "import indexStore from '/stores/indexStore'\nimport globalStore from '/stores/globalStore'\n\nPage({\n\n data: {\n private"
},
{
"path": "examples/alipay/pages/index/index.json",
"chars": 70,
"preview": "{\n \"usingComponents\":{\n \"header\":\"/components/header/header\"\n }\n}"
},
{
"path": "examples/alipay/stores/globalStore.js",
"chars": 570,
"preview": "// 全局store\nimport create from 'mini-stores'\n\nclass Store extends create.Store {\n\n data = {\n language: \"zh_cn\",\n u"
},
{
"path": "examples/alipay/stores/helloStore.js",
"chars": 227,
"preview": "import create from 'mini-stores'\n\nclass Store extends create.Store {\n\n data = {\n title: 'Hello页',\n }\n\n onChangeTit"
},
{
"path": "examples/alipay/stores/indexStore.js",
"chars": 236,
"preview": "import create from 'mini-stores'\n\nclass Store extends create.Store {\n\n data = {\n title: '首页',\n a: {\n b: {\n "
},
{
"path": "examples/baidu/app.css",
"chars": 0,
"preview": ""
},
{
"path": "examples/baidu/app.js",
"chars": 9,
"preview": "App({});\n"
},
{
"path": "examples/baidu/app.json",
"chars": 280,
"preview": "{\n \"pages\": [\n \"pages/index/index\",\n \"pages/hello/hello\"\n ],\n \"window\": {\n \"navigationBarB"
},
{
"path": "examples/baidu/components/header/header.css",
"chars": 166,
"preview": ".comm-header {\n padding: 30rpx 0;\n background-color: lightgreen;\n font-weight: bold;\n font-size: 30rpx;\n line-heigh"
},
{
"path": "examples/baidu/components/header/header.js",
"chars": 568,
"preview": "const helloStore = require('../../stores/helloStore')\nconst indexStore = require('../../stores/indexStore')\nconst global"
},
{
"path": "examples/baidu/components/header/header.json",
"chars": 23,
"preview": "{\n \"component\": true\n}"
},
{
"path": "examples/baidu/components/header/header.swan",
"chars": 499,
"preview": "<view class=\"comm-header\">\n <view style=\"margin: 20rpx; font-size: 38rpx; color: blue\">\n Hello页标题:{{$hello.title}}\n "
},
{
"path": "examples/baidu/package.json",
"chars": 251,
"preview": "{\n \"name\": \"demo\",\n \"version\": \"1.0.0\",\n \"description\": \"\",\n \"main\": \"app.js\",\n \"scripts\": {\n \"test\": \"echo \\\"Er"
},
{
"path": "examples/baidu/pages/hello/hello.css",
"chars": 186,
"preview": ".hello {\n height: 100vh;\n display: flex;\n flex-direction: column;\n justify-content: space-between;\n}\n\n.hello-title {"
},
{
"path": "examples/baidu/pages/hello/hello.js",
"chars": 492,
"preview": "const helloStore = require('../../stores/helloStore')\nconst globalStore = require('../../stores/globalStore')\n\nPage({\n\n "
},
{
"path": "examples/baidu/pages/hello/hello.json",
"chars": 70,
"preview": "{\n \"usingComponents\":{\n \"header\":\"/components/header/header\"\n }\n}"
},
{
"path": "examples/baidu/pages/hello/hello.swan",
"chars": 319,
"preview": "<view class=\"hello\">\n <header />\n <view>\n <button type=\"primary\" style=\"margin: auto; width: 300rpx\" bind:tap=\"hand"
},
{
"path": "examples/baidu/pages/index/index.css",
"chars": 208,
"preview": ".index {\n height: 100vh;\n display: flex;\n flex-direction: column;\n justify-content: space-between;\n text-align: cen"
},
{
"path": "examples/baidu/pages/index/index.js",
"chars": 557,
"preview": "const indexStore = require('../../stores/indexStore')\nconst globalStore = require('../../stores/globalStore')\n\nPage({\n\n "
},
{
"path": "examples/baidu/pages/index/index.json",
"chars": 70,
"preview": "{\n \"usingComponents\":{\n \"header\":\"/components/header/header\"\n }\n}"
},
{
"path": "examples/baidu/pages/index/index.swan",
"chars": 351,
"preview": "<view class=\"index\">\n <header />\n <view class=\"index-title\">{{$index.title}}</view>\n <view>{{$index.a.b.c}}</view>\n "
},
{
"path": "examples/baidu/project.swan.json",
"chars": 393,
"preview": "{\n \"host\": \"baiduboxapp\",\n \"projectname\": \"swan\",\n \"setting\": {\n \"urlCheck\": true\n },\n \"swan\": {\n "
},
{
"path": "examples/baidu/stores/globalStore.js",
"chars": 578,
"preview": "// 全局store\nconst create = require('mini-stores')\n\nclass Store extends create.Store {\n\n data = {\n language: \"zh_cn\",\n"
},
{
"path": "examples/baidu/stores/helloStore.js",
"chars": 237,
"preview": "const create = require('mini-stores')\n\nclass Store extends create.Store {\n \n data = {\n title: 'Hello页',\n }\n\n onCh"
},
{
"path": "examples/baidu/stores/indexStore.js",
"chars": 241,
"preview": "const create = require('mini-stores')\n\nclass Store extends create.Store {\n data = {\n title: '首页',\n a: {\n b: "
},
{
"path": "examples/bytedance/app.js",
"chars": 66,
"preview": "App({\n\n onLaunch(options) {\n\n },\n\n onShow(options) {\n\n },\n});\n"
},
{
"path": "examples/bytedance/app.json",
"chars": 129,
"preview": "{\n \"pages\": [\n \"pages/index/index\",\n \"pages/hello/hello\"\n ],\n \"window\": {\n \"navigationBarTitleText\": \"小程序多状态"
},
{
"path": "examples/bytedance/app.ttss",
"chars": 0,
"preview": ""
},
{
"path": "examples/bytedance/components/header/header.js",
"chars": 541,
"preview": "const helloStore = require('../../stores/helloStore')\nconst indexStore = require('../../stores/indexStore')\nconst global"
},
{
"path": "examples/bytedance/components/header/header.json",
"chars": 23,
"preview": "{\n \"component\": true\n}"
},
{
"path": "examples/bytedance/components/header/header.ttml",
"chars": 498,
"preview": "<view class=\"comm-header\">\n <view style=\"margin: 20rpx; font-size: 38rpx; color: blue\">\n Hello页标题:{{$hello.title}}\n "
},
{
"path": "examples/bytedance/components/header/header.ttss",
"chars": 166,
"preview": ".comm-header {\n padding: 30rpx 0;\n background-color: lightgreen;\n font-weight: bold;\n font-size: 30rpx;\n line-heigh"
},
{
"path": "examples/bytedance/package.json",
"chars": 251,
"preview": "{\n \"name\": \"demo\",\n \"version\": \"1.0.0\",\n \"description\": \"\",\n \"main\": \"app.js\",\n \"scripts\": {\n \"test\": \"echo \\\"Er"
},
{
"path": "examples/bytedance/pages/hello/hello.js",
"chars": 463,
"preview": "const helloStore = require('../../stores/helloStore')\nconst globalStore = require('../../stores/globalStore')\n\nPage({\n\n "
},
{
"path": "examples/bytedance/pages/hello/hello.json",
"chars": 70,
"preview": "{\n \"usingComponents\":{\n \"header\":\"/components/header/header\"\n }\n}"
},
{
"path": "examples/bytedance/pages/hello/hello.ttml",
"chars": 317,
"preview": "<view class=\"hello\">\n <header />\n <view>\n <button type=\"primary\" style=\"margin: auto; width: 300rpx\" bindtap=\"handl"
},
{
"path": "examples/bytedance/pages/hello/hello.ttss",
"chars": 186,
"preview": ".hello {\n height: 100vh;\n display: flex;\n flex-direction: column;\n justify-content: space-between;\n}\n\n.hello-title {"
},
{
"path": "examples/bytedance/pages/index/index.js",
"chars": 476,
"preview": "const indexStore = require('../../stores/indexStore')\nconst globalStore = require('../../stores/globalStore')\n\nPage({\n\n "
},
{
"path": "examples/bytedance/pages/index/index.json",
"chars": 70,
"preview": "{\n \"usingComponents\":{\n \"header\":\"/components/header/header\"\n }\n}"
},
{
"path": "examples/bytedance/pages/index/index.ttml",
"chars": 349,
"preview": "<view class=\"index\">\n <header />\n <view class=\"index-title\">{{$index.title}}</view>\n <view>{{$index.a.b.c}}</view>\n "
},
{
"path": "examples/bytedance/pages/index/index.ttss",
"chars": 208,
"preview": ".index {\n height: 100vh;\n display: flex;\n flex-direction: column;\n justify-content: space-between;\n text-align: cen"
},
{
"path": "examples/bytedance/project.config.json",
"chars": 1687,
"preview": "{\n \"description\": \"项目配置文件\",\n \"packOptions\": {\n \"ignore\": []\n },\n \"setting\": {\n \"bundle\": false"
},
{
"path": "examples/bytedance/sitemap.json",
"chars": 159,
"preview": "{\n \"desc\": \"关于本文件的更多信息,请参考文档 https://developers.weixin.qq.com/miniprogram/dev/framework/sitemap.html\",\n \"rules\": [{\n "
},
{
"path": "examples/bytedance/stores/globalStore.js",
"chars": 577,
"preview": "// 全局store\nconst create = require('mini-stores')\n\nclass Store extends create.Store {\n\n data = {\n language: \"zh_cn\",\n"
},
{
"path": "examples/bytedance/stores/helloStore.js",
"chars": 235,
"preview": "\nconst create = require('mini-stores')\n\nclass Store extends create.Store {\n\n data = {\n title: 'Hello页',\n }\n\n onCha"
},
{
"path": "examples/bytedance/stores/indexStore.js",
"chars": 244,
"preview": "\nconst create = require('mini-stores')\n\nclass Store extends create.Store {\n\n data = {\n title: '首页',\n a: {\n b"
},
{
"path": "examples/dd/app.acss",
"chars": 0,
"preview": ""
},
{
"path": "examples/dd/app.js",
"chars": 66,
"preview": "App({\n\n onLaunch(options) {\n\n },\n\n onShow(options) {\n\n },\n});\n"
},
{
"path": "examples/dd/app.json",
"chars": 120,
"preview": "{\n \"pages\": [\n \"pages/index/index\",\n \"pages/hello/hello\"\n ],\n \"window\": {\n \"defaultTitle\": \"小程序多状态管理\"\n }\n}\n"
},
{
"path": "examples/dd/components/header/header.acss",
"chars": 166,
"preview": ".comm-header {\n padding: 30rpx 0;\n background-color: lightgreen;\n font-weight: bold;\n font-size: 30rpx;\n line-heigh"
},
{
"path": "examples/dd/components/header/header.axml",
"chars": 496,
"preview": "<view class=\"comm-header\">\n <view style=\"margin: 20rpx; font-size: 38rpx; color: blue\">\n Hello页标题:{{$hello.title}}\n "
},
{
"path": "examples/dd/components/header/header.js",
"chars": 472,
"preview": "import helloStore from '/stores/helloStore'\nimport indexStore from '/stores/indexStore'\nimport globalStore from '/stores"
},
{
"path": "examples/dd/components/header/header.json",
"chars": 23,
"preview": "{\n \"component\": true\n}"
},
{
"path": "examples/dd/package.json",
"chars": 251,
"preview": "{\n \"name\": \"demo\",\n \"version\": \"1.0.0\",\n \"description\": \"\",\n \"main\": \"app.js\",\n \"scripts\": {\n \"test\": \"echo \\\"Er"
},
{
"path": "examples/dd/pages/hello/hello.acss",
"chars": 186,
"preview": ".hello {\n height: 100vh;\n display: flex;\n flex-direction: column;\n justify-content: space-between;\n}\n\n.hello-title {"
},
{
"path": "examples/dd/pages/hello/hello.axml",
"chars": 313,
"preview": "<view class=\"hello\">\n <header />\n <view>\n <button type=\"primary\" style=\"margin: auto; width: 300rpx\" onTap=\"handleC"
},
{
"path": "examples/dd/pages/hello/hello.js",
"chars": 445,
"preview": "import helloStore from '/stores/helloStore'\nimport globalStore from '/stores/globalStore'\n\nPage({\n\n data: {},\n\n onLoad"
},
{
"path": "examples/dd/pages/hello/hello.json",
"chars": 70,
"preview": "{\n \"usingComponents\":{\n \"header\":\"/components/header/header\"\n }\n}"
},
{
"path": "examples/dd/pages/index/index.acss",
"chars": 208,
"preview": ".index {\n height: 100vh;\n display: flex;\n flex-direction: column;\n justify-content: space-between;\n text-align: cen"
},
{
"path": "examples/dd/pages/index/index.axml",
"chars": 345,
"preview": "<view class=\"index\">\n <header />\n <view class=\"index-title\">{{$index.title}}</view>\n <view>{{$index.a.b.c}}</view>\n "
},
{
"path": "examples/dd/pages/index/index.js",
"chars": 457,
"preview": "import indexStore from '/stores/indexStore'\nimport globalStore from '/stores/globalStore'\n\nPage({\n\n data: {\n private"
},
{
"path": "examples/dd/pages/index/index.json",
"chars": 70,
"preview": "{\n \"usingComponents\":{\n \"header\":\"/components/header/header\"\n }\n}"
},
{
"path": "examples/dd/stores/globalStore.js",
"chars": 570,
"preview": "// 全局store\nimport create from 'mini-stores'\n\nclass Store extends create.Store {\n\n data = {\n language: \"zh_cn\",\n u"
},
{
"path": "examples/dd/stores/helloStore.js",
"chars": 228,
"preview": "\nimport create from 'mini-stores'\n\nclass Store extends create.Store {\n\n data = {\n title: 'Hello页',\n }\n\n onChangeTi"
},
{
"path": "examples/dd/stores/indexStore.js",
"chars": 237,
"preview": "\nimport create from 'mini-stores'\n\nclass Store extends create.Store {\n\n data = {\n title: '首页',\n a: {\n b: {\n "
},
{
"path": "examples/jd/app.js",
"chars": 66,
"preview": "App({\n\n onLaunch(options) {\n\n },\n\n onShow(options) {\n\n },\n});\n"
},
{
"path": "examples/jd/app.json",
"chars": 129,
"preview": "{\n \"pages\": [\n \"pages/index/index\",\n \"pages/hello/hello\"\n ],\n \"window\": {\n \"navigationBarTitleText\": \"小程序多状态"
},
{
"path": "examples/jd/app.jxss",
"chars": 0,
"preview": ""
},
{
"path": "examples/jd/components/header/header.js",
"chars": 532,
"preview": "const helloStore = require('../../stores/helloStore')\nconst indexStore = require('../../stores/indexStore')\nconst global"
},
{
"path": "examples/jd/components/header/header.json",
"chars": 23,
"preview": "{\n \"component\": true\n}"
},
{
"path": "examples/jd/components/header/header.jxml",
"chars": 498,
"preview": "<view class=\"comm-header\">\n <view style=\"margin: 20rpx; font-size: 38rpx; color: blue\">\n Hello页标题:{{$hello.title}}\n "
},
{
"path": "examples/jd/components/header/header.jxss",
"chars": 166,
"preview": ".comm-header {\n padding: 30rpx 0;\n background-color: lightgreen;\n font-weight: bold;\n font-size: 30rpx;\n line-heigh"
},
{
"path": "examples/jd/package.json",
"chars": 251,
"preview": "{\n \"name\": \"demo\",\n \"version\": \"1.0.0\",\n \"description\": \"\",\n \"main\": \"app.js\",\n \"scripts\": {\n \"test\": \"echo \\\"Er"
},
{
"path": "examples/jd/pages/hello/hello.js",
"chars": 465,
"preview": "const helloStore = require('../../stores/helloStore')\nconst globalStore = require('../../stores/globalStore')\n\nPage({\n\n "
},
{
"path": "examples/jd/pages/hello/hello.json",
"chars": 70,
"preview": "{\n \"usingComponents\":{\n \"header\":\"/components/header/header\"\n }\n}"
},
{
"path": "examples/jd/pages/hello/hello.jxml",
"chars": 317,
"preview": "<view class=\"hello\">\n <header />\n <view>\n <button type=\"primary\" style=\"margin: auto; width: 300rpx\" bindtap=\"handl"
},
{
"path": "examples/jd/pages/hello/hello.jxss",
"chars": 186,
"preview": ".hello {\n height: 100vh;\n display: flex;\n flex-direction: column;\n justify-content: space-between;\n}\n\n.hello-title {"
},
{
"path": "examples/jd/pages/index/index.js",
"chars": 513,
"preview": "const indexStore = require('../../stores/indexStore')\nconst globalStore = require('../../stores/globalStore')\n\nPage({\n\n "
},
{
"path": "examples/jd/pages/index/index.json",
"chars": 70,
"preview": "{\n \"usingComponents\":{\n \"header\":\"/components/header/header\"\n }\n}"
},
{
"path": "examples/jd/pages/index/index.jxml",
"chars": 349,
"preview": "<view class=\"index\">\n <header />\n <view class=\"index-title\">{{$index.title}}</view>\n <view>{{$index.a.b.c}}</view>\n "
},
{
"path": "examples/jd/pages/index/index.jxss",
"chars": 208,
"preview": ".index {\n height: 100vh;\n display: flex;\n flex-direction: column;\n justify-content: space-between;\n text-align: cen"
},
{
"path": "examples/jd/project.config.json",
"chars": 1426,
"preview": "{\n \"description\": \"项目配置文件\",\n \"packOptions\": {\n \"ignore\": []\n },\n \"setting\": {\n \"bundle\": false,\n \"userConfi"
},
{
"path": "examples/jd/sitemap.json",
"chars": 159,
"preview": "{\n \"desc\": \"关于本文件的更多信息,请参考文档 https://developers.weixin.qq.com/miniprogram/dev/framework/sitemap.html\",\n \"rules\": [{\n "
},
{
"path": "examples/jd/stores/globalStore.js",
"chars": 577,
"preview": "// 全局store\nconst create = require('mini-stores')\n\nclass Store extends create.Store {\n\n data = {\n language: \"zh_cn\",\n"
},
{
"path": "examples/jd/stores/helloStore.js",
"chars": 235,
"preview": "\nconst create = require('mini-stores')\n\nclass Store extends create.Store {\n\n data = {\n title: 'Hello页',\n }\n\n onCha"
},
{
"path": "examples/jd/stores/indexStore.js",
"chars": 244,
"preview": "\nconst create = require('mini-stores')\n\nclass Store extends create.Store {\n\n data = {\n title: '首页',\n a: {\n b"
},
{
"path": "examples/qq/app.js",
"chars": 66,
"preview": "App({\n\n onLaunch(options) {\n\n },\n\n onShow(options) {\n\n },\n});\n"
},
{
"path": "examples/qq/app.json",
"chars": 129,
"preview": "{\n \"pages\": [\n \"pages/index/index\",\n \"pages/hello/hello\"\n ],\n \"window\": {\n \"navigationBarTitleText\": \"小程序多状态"
},
{
"path": "examples/qq/app.qss",
"chars": 0,
"preview": ""
},
{
"path": "examples/qq/components/header/header.js",
"chars": 537,
"preview": "const helloStore = require('../../stores/helloStore')\nconst indexStore = require('../../stores/indexStore')\nconst global"
},
{
"path": "examples/qq/components/header/header.json",
"chars": 23,
"preview": "{\n \"component\": true\n}"
},
{
"path": "examples/qq/components/header/header.qml",
"chars": 498,
"preview": "<view class=\"comm-header\">\n <view style=\"margin: 20rpx; font-size: 38rpx; color: blue\">\n Hello页标题:{{$hello.title}}\n "
},
{
"path": "examples/qq/components/header/header.qss",
"chars": 166,
"preview": ".comm-header {\n padding: 30rpx 0;\n background-color: lightgreen;\n font-weight: bold;\n font-size: 30rpx;\n line-heigh"
},
{
"path": "examples/qq/package.json",
"chars": 251,
"preview": "{\n \"name\": \"demo\",\n \"version\": \"1.0.0\",\n \"description\": \"\",\n \"main\": \"app.js\",\n \"scripts\": {\n \"test\": \"echo \\\"Er"
},
{
"path": "examples/qq/pages/hello/hello.js",
"chars": 465,
"preview": "const helloStore = require('../../stores/helloStore')\nconst globalStore = require('../../stores/globalStore')\n\nPage({\n\n "
},
{
"path": "examples/qq/pages/hello/hello.json",
"chars": 70,
"preview": "{\n \"usingComponents\":{\n \"header\":\"/components/header/header\"\n }\n}"
},
{
"path": "examples/qq/pages/hello/hello.qml",
"chars": 317,
"preview": "<view class=\"hello\">\n <header />\n <view>\n <button type=\"primary\" style=\"margin: auto; width: 300rpx\" bindtap=\"handl"
},
{
"path": "examples/qq/pages/hello/hello.qss",
"chars": 186,
"preview": ".hello {\n height: 100vh;\n display: flex;\n flex-direction: column;\n justify-content: space-between;\n}\n\n.hello-title {"
},
{
"path": "examples/qq/pages/index/index.js",
"chars": 477,
"preview": "const indexStore = require('../../stores/indexStore')\nconst globalStore = require('../../stores/globalStore')\n\nPage({\n\n "
},
{
"path": "examples/qq/pages/index/index.json",
"chars": 70,
"preview": "{\n \"usingComponents\":{\n \"header\":\"/components/header/header\"\n }\n}"
},
{
"path": "examples/qq/pages/index/index.qml",
"chars": 349,
"preview": "<view class=\"index\">\n <header />\n <view class=\"index-title\">{{$index.title}}</view>\n <view>{{$index.a.b.c}}</view>\n "
},
{
"path": "examples/qq/pages/index/index.qss",
"chars": 208,
"preview": ".index {\n height: 100vh;\n display: flex;\n flex-direction: column;\n justify-content: space-between;\n text-align: cen"
},
{
"path": "examples/qq/project.config.json",
"chars": 1385,
"preview": "{\n\t\"description\": \"项目配置文件\",\n\t\"packOptions\": {\n\t\t\"ignore\": []\n\t},\n\t\"setting\": {\n\t\t\"bundle\": false,\n\t\t\"userConfirmedBundle"
},
{
"path": "examples/qq/sitemap.json",
"chars": 159,
"preview": "{\n \"desc\": \"关于本文件的更多信息,请参考文档 https://developers.weixin.qq.com/miniprogram/dev/framework/sitemap.html\",\n \"rules\": [{\n "
},
{
"path": "examples/qq/stores/globalStore.js",
"chars": 577,
"preview": "// 全局store\nconst create = require('mini-stores')\n\nclass Store extends create.Store {\n\n data = {\n language: \"zh_cn\",\n"
},
{
"path": "examples/qq/stores/helloStore.js",
"chars": 234,
"preview": "const create = require('mini-stores')\n\nclass Store extends create.Store {\n\n data = {\n title: 'Hello页',\n }\n\n onChan"
},
{
"path": "examples/qq/stores/indexStore.js",
"chars": 243,
"preview": "const create = require('mini-stores')\n\nclass Store extends create.Store {\n\n data = {\n title: '首页',\n a: {\n b:"
},
{
"path": "examples/wx/app.js",
"chars": 66,
"preview": "App({\n\n onLaunch(options) {\n\n },\n\n onShow(options) {\n\n },\n});\n"
},
{
"path": "examples/wx/app.json",
"chars": 188,
"preview": "{\n \"pages\": [\n \"pages/index/index\",\n \"pages/hello/hello\"\n ],\n \"window\": {\n \"navigationBarT"
},
{
"path": "examples/wx/app.wxss",
"chars": 0,
"preview": ""
},
{
"path": "examples/wx/components/header/header.js",
"chars": 540,
"preview": "const helloStore = require('../../stores/helloStore')\nconst indexStore = require('../../stores/indexStore')\nconst global"
},
{
"path": "examples/wx/components/header/header.json",
"chars": 23,
"preview": "{\n \"component\": true\n}"
},
{
"path": "examples/wx/components/header/header.wxml",
"chars": 498,
"preview": "<view class=\"comm-header\">\n <view style=\"margin: 20rpx; font-size: 38rpx; color: blue\">\n Hello页标题:{{$hello.title}}\n "
},
{
"path": "examples/wx/components/header/header.wxss",
"chars": 166,
"preview": ".comm-header {\n padding: 30rpx 0;\n background-color: lightgreen;\n font-weight: bold;\n font-size: 30rpx;\n line-heigh"
},
{
"path": "examples/wx/package.json",
"chars": 251,
"preview": "{\n \"name\": \"demo\",\n \"version\": \"1.0.0\",\n \"description\": \"\",\n \"main\": \"app.js\",\n \"scripts\": {\n \"test\": \"echo \\\"Er"
},
{
"path": "examples/wx/pages/hello/hello.js",
"chars": 466,
"preview": "const helloStore = require('../../stores/helloStore')\nconst globalStore = require('../../stores/globalStore')\n\nPage({\n "
},
{
"path": "examples/wx/pages/hello/hello.json",
"chars": 70,
"preview": "{\n \"usingComponents\":{\n \"header\":\"/components/header/header\"\n }\n}"
},
{
"path": "examples/wx/pages/hello/hello.wxml",
"chars": 317,
"preview": "<view class=\"hello\">\n <header />\n <view>\n <button type=\"primary\" style=\"margin: auto; width: 300rpx\" bindtap=\"handl"
},
{
"path": "examples/wx/pages/hello/hello.wxss",
"chars": 186,
"preview": ".hello {\n height: 100vh;\n display: flex;\n flex-direction: column;\n justify-content: space-between;\n}\n\n.hello-title {"
},
{
"path": "examples/wx/pages/index/index.js",
"chars": 558,
"preview": "const indexStore = require('../../stores/indexStore')\nconst globalStore = require('../../stores/globalStore');\n\nPage({\n\n"
},
{
"path": "examples/wx/pages/index/index.json",
"chars": 70,
"preview": "{\n \"usingComponents\":{\n \"header\":\"/components/header/header\"\n }\n}"
},
{
"path": "examples/wx/pages/index/index.wxml",
"chars": 349,
"preview": "<view class=\"index\">\n <header />\n <view class=\"index-title\">{{$index.title}}</view>\n <view>{{$index.a.b.c}}</view>\n "
},
{
"path": "examples/wx/pages/index/index.wxss",
"chars": 208,
"preview": ".index {\n height: 100vh;\n display: flex;\n flex-direction: column;\n justify-content: space-between;\n text-align: cen"
},
{
"path": "examples/wx/project.config.json",
"chars": 1261,
"preview": "{\n \"description\": \"项目配置文件\",\n \"packOptions\": {\n \"ignore\": [],\n \"include\": []\n },\n \"setting\": {\n \"bundle\": fa"
},
{
"path": "examples/wx/sitemap.json",
"chars": 159,
"preview": "{\n \"desc\": \"关于本文件的更多信息,请参考文档 https://developers.weixin.qq.com/miniprogram/dev/framework/sitemap.html\",\n \"rules\": [{\n "
},
{
"path": "examples/wx/stores/globalStore.js",
"chars": 577,
"preview": "// 全局store\nconst create = require('mini-stores')\n\nclass Store extends create.Store {\n\n data = {\n language: \"zh_cn\",\n"
},
{
"path": "examples/wx/stores/helloStore.js",
"chars": 234,
"preview": "const create = require('mini-stores')\n\nclass Store extends create.Store {\n\n data = {\n title: 'Hello页',\n }\n\n onChan"
},
{
"path": "examples/wx/stores/indexStore.js",
"chars": 243,
"preview": "const create = require('mini-stores')\n\nclass Store extends create.Store {\n\n data = {\n title: '首页',\n a: {\n b:"
},
{
"path": "package.json",
"chars": 1220,
"preview": "{\n \"name\": \"mini-stores\",\n \"version\": \"2.3.0\",\n \"description\": \"小程序多状态管理 - 解决跨页面跨组件间通信,简洁小巧高性能,支持微信、支付宝、钉钉、百度、字节、QQ等小"
},
{
"path": "readme.md",
"chars": 4791,
"preview": "# mini-stores - 小程序多状态管理\n\n- [前言](#前言)\n- [安装](#安装)\n- [使用](#使用)\n - [创建store](#创建store)\n - [页面内使用](#页面内使用)\n - [组件内使用](#组"
},
{
"path": "src/index.ts",
"chars": 8258,
"preview": "const TYPE_ARRAY = '[object Array]';\nconst TYPE_OBJECT = '[object Object]';\nconst TYPE_FUNCTION = '[object Function]';\n\n"
},
{
"path": "tsconfig.json",
"chars": 365,
"preview": "{\n \"compilerOptions\": {\n \"target\": \"esnext\",\n \"module\": \"esnext\",\n \"declaration\": true,\n \"emitDeclarationOn"
}
]
About this extraction
This page contains the full source code of the linjc/mini-stores GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 150 files (55.8 KB), approximately 21.2k tokens, and a symbol index with 164 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.