New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

onlystate

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

onlystate - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

dist/devTools.d.ts

172

dist/only-state.js
/*
* only-state.js 0.0.3
* only-state.js 0.0.4
* author:webszy
* date:2022/5/10 下午12:07:08
* date:2022/5/10 下午5:38:57
*/

@@ -175,3 +175,4 @@ import { reactive, computed, toRefs } from 'vue';

const initDevtools = (app,store) => {
// @ts-ignore
const initDevtools = (app, store) => {
const stateType = 'routing properties';

@@ -189,3 +190,3 @@ const INSPECTOR_ID = 'zState-inspector';

]
}, api => {
}, (api) => {
// Use the API here

@@ -200,21 +201,22 @@ setInterval(() => {

});
api.on.getInspectorTree((payload, context) => {
api.on.getInspectorTree((payload) => {
if (payload.inspectorId === INSPECTOR_ID) {
payload.rootNodes = [{
id: 'root',
label: 'zState',
children: []
}];
id: 'root',
label: 'zState',
children: []
}];
}
});
api.on.getInspectorState((payload, context) => {
api.on.getInspectorState((payload) => {
if (payload.nodeId === 'root') {
const getters = [];
Object.keys(store.getters).forEach(key => {
getters.push({
key,
value:store.getters[key].value
if (store.getters) {
Object.keys(store.getters).forEach((key) => {
getters.push({
key,
value: store.getters[key].value
});
});
});
}
const state = [];

@@ -224,7 +226,6 @@ Object.keys(store.state).forEach(key => {

key,
value:store.state[key],
value: store.state[key],
editable: true
});
});
payload.state = {

@@ -235,45 +236,44 @@ state,

}
});
});
};
const isFunction = (fn) => typeof fn === "function";
const isObject = (obj) => obj!== null && typeof obj === "object" && Array.isArray(obj) === false;
const concatAllParams = (key,...rest)=>{
const isObject = (obj) => obj !== null && typeof obj === "object" && Array.isArray(obj) === false;
const concatAllParams = (key, ...rest) => {
const params = [].concat(rest);
if(Array.isArray(key)){
if (Array.isArray(key)) {
params.unshift(...key);
} else {
}
else {
params.unshift(key);
}
return params.filter(e=>e&&e!=='')
return params.filter(e => e && e !== '');
};
// @ts-ignore
const originState = {};
let _ZState = '[ZState warning] firstly,you should use defineState() to define a state';
const _State = {
state: {},
getters: {}
};
const installStore = {
install(app) {
app.config.globalProperties.$zState = _ZState;
initDevtools(app,_ZState);
app.config.globalProperties.$ostate = _State;
initDevtools(app, _State);
}
};
const defineState = (state,getters)=>{
_ZState = {
state: {},
getters: {}
};
if(isObject(state)){
Object.assign(originState,state); // 保留原始state
_ZState.state = reactive(state);
} else {
console.log('[ZState warning] you must define a state');
return false
const defineState = (state, getters) => {
if (isObject(state)) {
Object.assign(originState, state); // 保留原始state
_State.state = reactive(state);
}
else {
console.log('[onlyState warning] you must define a state');
return false;
}
if (isObject(getters) && Object.keys(getters).length > 0) {
const keys = Object.keys(getters);
const hasDuplicateKey = keys.some(key => key in state);
if(hasDuplicateKey){
if (hasDuplicateKey) {
console.log(`[ZState warning] some key is already defined in state,it will be overrided by storeToRefs`);

@@ -283,67 +283,75 @@ }

if (isFunction(getters[key])) {
const func = ()=> getters[key](_ZState.state);
_ZState.getters[key] = computed(func);
const func = () => getters[key](_State.state);
_State.getters[key] = computed(func);
}
});
}
return installStore
return installStore;
};
const useState = (key,...rest)=>{
const params = concatAllParams(key,...rest);
const useState = (key, ...rest) => {
const params = concatAllParams(key, ...rest);
const len = params.length;
const hasParams = len >= 0;
const hasKey = keyName => keyName in _ZState.state;
const getOne = keyName => hasKey(keyName) ? toRefs(_ZState.state)[keyName] : undefined;
if(len === 0){
return _ZState.state
const hasKey = (keyName) => keyName in _State.state;
const getOne = (keyName) => hasKey(keyName) ? toRefs(_State.state)[keyName] : undefined;
if (len === 0) {
return _State.state;
}
if(hasParams && params.some(e=>typeof e !== 'string')){
if (hasParams && params.some(e => typeof e !== 'string')) {
console.error('use Function Alert: the key of use must be String or String Array');
return
return;
}
if (len === 1){
return getOne(params[0])
} else {
return params.map(getOne)
if (len === 1) {
return getOne(params[0]);
}
else {
return params.map(getOne);
}
};
const useGetters = (key,...rest)=>{
if(Object.keys(_ZState.getters).length === 0){
console.log(`[ZState warning] make sure you define getters`);
return false
const useGetters = (key, ...rest) => {
if (!_State.getters) {
return undefined;
}
const params = concatAllParams(key,...rest);
if (Object.keys(_State.getters).length === 0) {
console.log(`[onlyState warning] make sure you define getters`);
return false;
}
const params = concatAllParams(key, ...rest);
const len = params.length;
const hasParams = len >= 0;
const hasKey = keyName => keyName in _ZState.getters;
const getOne = keyName => hasKey(keyName) ? _ZState.getters[keyName] : undefined;
if(len === 0){
return _ZState.getters
const hasKey = (keyName) => keyName in _State.getters;
const getOne = (keyName) => hasKey(keyName) ? _State.getters[keyName] : undefined;
if (len === 0) {
return _State.getters;
}
if(hasParams && params.some(e=>typeof e !== 'string')){
if (hasParams && params.some(e => typeof e !== 'string')) {
console.error('use Function Alert: the key of use must be String or String Array');
return
return;
}
if (len === 1){
return getOne(params[0])
} else {
return params.map(getOne)
if (len === 1) {
return getOne(params[0]);
}
else {
return params.map(getOne);
}
};
const stateToRefs = () => {
return {..._ZState.getters,...toRefs(_ZState.state)};
const getters = _State.getters ? _State.getters.getters : {};
return { ...getters, ...toRefs(_State.state) };
};
const resetState = ()=>{
Object.assign(_ZState.state,originState);
const resetState = () => {
Object.assign(_State.state, originState);
};
const patchState = (desire)=>{
if(isObject(desire)){
Object.assign(_ZState.state,desire);
} else if(isFunction(desire)){
desire(_ZState.state);
} else {
console.log('[ZState warning] $patch function receive an object or a function');
const patchState = (desire) => {
if (isObject(desire)) {
Object.assign(_State.state, desire);
}
else if (isFunction(desire)) {
desire(_State.state);
}
else {
console.log('[onlyState warning] $patch function receive an object or a function');
}
};
export { defineState as default, defineState, installStore, patchState, resetState, stateToRefs, useGetters, useState };
{
"name": "onlystate",
"version": "0.0.3",
"version": "0.0.4",
"description": "A state and only state management library for Vue3",

@@ -13,3 +13,8 @@ "main": "/dist/only-state.js",

"homepage": "https://github.com/webszy/only-state#readme",
"keywords": ["vue3", "state", "state management","shared state"],
"keywords": [
"vue3",
"state",
"state management",
"shared state"
],
"author": "webszy",

@@ -24,4 +29,6 @@ "license": "MIT",

"@rollup/plugin-node-resolve": "^13.3.0",
"rollup": "^2.72.1"
"@rollup/plugin-typescript": "^8.3.2",
"rollup": "^2.72.1",
"rollup-plugin-typescript2": "^0.31.2"
}
}
import { nodeResolve } from '@rollup/plugin-node-resolve';
import {version} from './package.json';
import typescript from 'rollup-plugin-typescript2';
export default {
input: "src/index.js", // 入口
input: "src/index.ts", // 入口
output: {

@@ -15,4 +17,7 @@ file: "dist/only-state.js", // 输出文件

}, // 出口
plugins: [nodeResolve({dedupe:['@vue/devtools-api']})], // 各种插件使用的配置
plugins: [
nodeResolve({dedupe:['@vue/devtools-api']}),
typescript({})
], // 各种插件使用的配置
external: ['vue'],// 外部依赖的配置
};
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc