Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

effector-vue

Package Overview
Dependencies
Maintainers
0
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

effector-vue - npm Package Compare versions

Comparing version 23.0.0 to 23.1.0

options-vue3.cjs.d.ts

9

composition.cjs.d.ts

@@ -1,2 +0,2 @@

import {ComputedRef, DeepReadonly, Ref, UnwrapRef} from '@vue/reactivity'
import {ComputedRef, DeepReadonly, EffectScope, Reactive, Ref, UnwrapRef} from '@vue/reactivity'
import {Domain, Store, Event, Effect, Scope} from 'effector'

@@ -20,3 +20,3 @@

type ExtractStore<T extends Record<string, Store<unknown>>> = {
[Key in keyof T]: T[Key] extends Store<infer U> ? Ref<UnwrapRef<U>> : never
[Key in keyof T]: T[Key] extends Store<infer U> ? Reactive<U> : never
}

@@ -26,3 +26,3 @@

<T>(vm: Store<T>): Ref<T>
<T extends Record<string, Store<any>>>(vm: T): ExtractStore<T>
<T extends Record<string, Store<any>>>(vm: T, scope?: EffectScope): ExtractStore<T>
}

@@ -40,5 +40,6 @@

): ComputedRef<Result>
export function useVModel<T>(vm: Store<T>): Ref<UnwrapRef<T>>
export function useVModel<T>(vm: Store<T>, scope?: EffectScope): Ref<UnwrapRef<T>>
export function useVModel<T extends Record<string, Store<any>>>(
vm: T,
scope?: EffectScope
): ExtractStore<T>

@@ -45,0 +46,0 @@ export function useStore<T>(store: Store<T>): DeepReadonly<Ref<T>>

@@ -1,2 +0,2 @@

function e(e,t){return t?t.getState(e):e.getState()}function t(){let e,t=i.getCurrentInstance(),o=null==t?void 0:t.appContext.config.globalProperties.scopeName;return o&&(e=i.inject(o)),{scopeName:o,scope:e}}function o(e){const t=i.unref(e);return i.isReactive(t)?i.toRaw(t):t}function n(e,t=[]){if(null===e||'object'!=typeof e)return e;const o=t.filter((t=>t.original===e))[0];if(o)return o.copy;const s=Array.isArray(e)?[]:{};return t.push({original:e,copy:s}),Object.keys(e).forEach((o=>{s[o]=n(e[o],t)})),s}function s(s,r,a){if(!effector.is.store(s))throw Error('expect useVModel argument to be a store');let{scope:c}=t(),u=i.ref(n(e(s,c))),l=0,f=0,p=effector.createWatch({unit:s,fn:e=>{l||(f=1,u.value=i.ref(n(e)).value)},scope:c});return i.onUnmounted((()=>{p()})),i.watch((()=>r&&a?a[r]:u.value),(e=>{if(l=1,!f){let t=i.ref(o(e)).value;s.setState(n(t))}f=0,l=0}),{deep:1,immediate:0}),u}function r(e,t){const o=t?e:e[0];var n;(e=>{if(!e)throw Error("expect first argument be an object")})(l(n=o)||(e=>'function'==typeof e)(n));let s=o.or;const a=o.and;if(a){const o=t?a:a[0];if(l(o)&&'and'in o){const o=r(a,t);e=o[0],s={...s,...o[1]}}else e=a}return[e,s]}function a(e,t){let s,r;t&&(r=i.computed(t),s=i.watch(r,(t=>{const s=o(t);e.set(n(s))}),{deep:1,immediate:1})),i.onMounted((()=>{if(void 0!==r){const t=o(r.value);e.open(n(t))}else e.open()})),i.onUnmounted((()=>{if(void 0!==r){const t=o(r.value);e.close(n(t))}else e.close();s&&s()}))}Object.defineProperty(exports,'__esModule',{value:1});var effector=require('effector'),i=require('vue');const c=e=>{throw Error(e)},u=(e,t)=>e!==t,l=e=>'object'==typeof e&&null!==e,f=(e,t={})=>(l(e)&&(f(e.or,t),(e=>{for(const s in e)n=s,(e=>void 0===e)(o=e[s])||'or'===n||'and'===n||(t[n]=o);var o,n})(e),f(e.and,t)),t);exports.createGate=(...e)=>{function t(e){a(t,(()=>e))}var o;const n=e&&(e=>l(e)&&(e.and||e.or))(e[0])?e:[{and:e}],[[s],i]=r(n),c=f({or:i,and:s}),u=null==s?void 0:s.domain,p=`${u?`${u.compositeName.fullName}/`:''}${(null==c?void 0:c.name)||'gate'}`,d=effector.createEvent({name:`${p}.set`,sid:c.sid?`${c.sid}|set`:void 0}),v=effector.createEvent({name:`${p}.open`,sid:c.sid?`${c.sid}|open`:void 0}),m=effector.createEvent({name:`${p}.close`,sid:c.sid?`${c.sid}|close`:void 0}),h=effector.createStore(Boolean(0),{name:`${p}.status`,serialize:'ignore'}),y=effector.createStore(null!==(o=null==s?void 0:s.defaultState)&&void 0!==o?o:null,{name:`${p}.state`,sid:null==c?void 0:c.sid});if(y.on(d,((e,t)=>t)),h.on(v,(()=>Boolean(1))).on(m,(()=>Boolean(0))),t.open=v,t.close=m,t.status=h,t.state=y,t.set=d,effector.sample({clock:v,target:d}),y.reset(m),null!=s&&s.domain){const{hooks:e}=s.domain;effector.launch({target:[e.store,e.store,e.event,e.event,e.event],params:[h,y,v,m,d]})}return t},exports.useGate=a,exports.useStore=o=>{effector.is.store(o)||c('expect useStore argument to be a store');let{scope:n}=t(),s=e(o,n),r=i.shallowRef(s),a=effector.createWatch({unit:o,fn:e=>{r.value=i.shallowRef(e).value},scope:n});return i.onUnmounted((()=>{a()})),i.readonly(r)},exports.useStoreMap=(o,n)=>{effector.is.store(o.store)||c('useStoreMap expects a store'),void 0!==o.keys&&'function'!=typeof o.keys&&c('useStoreMap expects keys as a function'),'function'!=typeof o.fn&&c('useStoreMap expects fn as a function');let s=n||t().scope,r=i.computed(o.keys?o.keys:()=>{}),a=o.updateFilter||u,l=e(o.store,s),f="object"==typeof l&&0==Array.isArray(l),p=f?i.shallowReactive(l):i.shallowRef(l),d=effector.createWatch({unit:o.store,fn:e=>{if(f)for(let t in e)a(e[t],p[t])&&(p[t]=e[t]);else void 0!==e&&a(e,p.value)&&(p.value=e)},scope:s});return i.onUnmounted((()=>{d()})),i.computed((()=>{let e=o.fn(f?p:p.value,r.value);return void 0!==e?e:o.defaultValue}))},exports.useUnit=o=>{const{scope:n}=t(),s=effector.is.unit(o);let r={};s?r={unit:o}:'@@unitShape'in o?'function'==typeof o['@@unitShape']?r=o['@@unitShape']():c('expect @@unitShape to be a function'):r=o;const a=Array.isArray(r),u=[],l=[];for(const e in r){const t=r[e];effector.is.unit(t)||c('expect useUnit argument to be a unit'),effector.is.event(t)||effector.is.effect(t)?l.push(e):u.push(e)}const f={};for(const t of u){const o=e(r[t],n),s=i.shallowRef(o),a=effector.createWatch({unit:r[t],fn:e=>{s.value=i.shallowRef(e).value},scope:n});f[t]={stop:a,ref:s}}if(i.onUnmounted((()=>{for(const e of Object.values(f))e.stop()})),s&&effector.is.store(o))return i.readonly(f.unit.ref);if(s&&effector.is.event(o))return effector.scopeBind(r.unit,{scope:n,safe:1});const p={};for(const e of l)p[e]=effector.scopeBind(r[e],{scope:n,safe:1});for(const[e,t]of Object.entries(f))p[e]=i.readonly(t.ref);return a?Object.values(p):p},exports.useVModel=e=>{if(effector.is.store(e))return s(e);const t=i.reactive({}),o=Object.fromEntries(Object.entries(e).map((([e,o])=>[e,s(o,e,t)])));for(const e in o)t[e]=o[e];return t};
function e(e,t){return t?t.getState(e):e.getState()}function t(){let e,t=c.getCurrentInstance(),o=null==t?void 0:t.appContext.config.globalProperties.scopeName;return o&&(e=c.inject(o)),{scopeName:o,scope:e}}function o(e,t=new Map){if(null===e||'object'!=typeof e)return e;const n=t.get(e);if(n)return n;const s=Array.isArray(e)?[]:{};t.set(e,s);for(const n of Object.keys(e))s[n]=o(e[n],t);return s}function n(n,s,r){if(!effector.is.store(n))throw Error('expect useVModel argument to be a store');const{scope:a}=t(),i=c.ref(o(e(n,a)));let u=0,l=0;const f=effector.createWatch({unit:n,fn:e=>{u||(l=1,i.value=o(e))},scope:a});return c.onScopeDispose((()=>{f()})),c.watch((()=>s&&r?r[s]:i.value),(e=>{u=1,l||n.setState(o(c.toRaw(e))),l=0,u=0}),{deep:1}),i}function s(e){const t=c.unref(e);return c.isReactive(t)?c.toRaw(t):t}function r(e,t){const o=t?e:e[0];var n;(e=>{if(!e)throw Error("expect first argument be an object")})(l(n=o)||(e=>'function'==typeof e)(n));let s=o.or;const a=o.and;if(a){const o=t?a:a[0];if(l(o)&&'and'in o){const o=r(a,t);e=o[0],s={...s,...o[1]}}else e=a}return[e,s]}function a(e,t){let n,r;t&&(r=c.computed(t),n=c.watch(r,(t=>{const n=s(t);e.set(o(n))}),{deep:1,immediate:1})),c.onMounted((()=>{if(void 0!==r){const t=s(r.value);e.open(o(t))}else e.open()})),c.onUnmounted((()=>{if(void 0!==r){const t=s(r.value);e.close(o(t))}else e.close();n&&n()}))}Object.defineProperty(exports,'__esModule',{value:1});var effector=require('effector'),c=require('vue');const i=e=>{throw Error(e)},u=(e,t)=>e!==t,l=e=>'object'==typeof e&&null!==e,f=(e,t={})=>(l(e)&&(f(e.or,t),(e=>{for(const s in e)n=s,(e=>void 0===e)(o=e[s])||'or'===n||'and'===n||(t[n]=o);var o,n})(e),f(e.and,t)),t);exports.createGate=(...e)=>{function t(e){a(t,(()=>e))}var o;const n=e&&(e=>l(e)&&(e.and||e.or))(e[0])?e:[{and:e}],[[s],c]=r(n),i=f({or:c,and:s}),u=null==s?void 0:s.domain,p=`${u?`${u.compositeName.fullName}/`:''}${(null==i?void 0:i.name)||'gate'}`,d=effector.createEvent({name:`${p}.set`,sid:i.sid?`${i.sid}|set`:void 0}),v=effector.createEvent({name:`${p}.open`,sid:i.sid?`${i.sid}|open`:void 0}),m=effector.createEvent({name:`${p}.close`,sid:i.sid?`${i.sid}|close`:void 0}),h=effector.createStore(Boolean(0),{name:`${p}.status`,serialize:'ignore'}),y=effector.createStore(null!==(o=null==s?void 0:s.defaultState)&&void 0!==o?o:null,{name:`${p}.state`,sid:null==i?void 0:i.sid});if(y.on(d,((e,t)=>t)),h.on(v,(()=>Boolean(1))).on(m,(()=>Boolean(0))),t.open=v,t.close=m,t.status=h,t.state=y,t.set=d,effector.sample({clock:v,target:d}),y.reset(m),null!=s&&s.domain){const{hooks:e}=s.domain;effector.launch({target:[e.store,e.store,e.event,e.event,e.event],params:[h,y,v,m,d]})}return t},exports.useGate=a,exports.useStore=o=>{effector.is.store(o)||i('expect useStore argument to be a store');let{scope:n}=t(),s=e(o,n),r=c.shallowRef(s),a=effector.createWatch({unit:o,fn:e=>{r.value=c.shallowRef(e).value},scope:n});return c.onUnmounted((()=>{a()})),c.readonly(r)},exports.useStoreMap=(o,n)=>{effector.is.store(o.store)||i('useStoreMap expects a store'),void 0!==o.keys&&'function'!=typeof o.keys&&i('useStoreMap expects keys as a function'),'function'!=typeof o.fn&&i('useStoreMap expects fn as a function');let s=n||t().scope,r=c.computed(o.keys?o.keys:()=>{}),a=o.updateFilter||u,l=e(o.store,s),f="object"==typeof l&&0==Array.isArray(l),p=f?c.shallowReactive(l):c.shallowRef(l),d=effector.createWatch({unit:o.store,fn:e=>{if(f)for(let t in e)a(e[t],p[t])&&(p[t]=e[t]);else void 0!==e&&a(e,p.value)&&(p.value=e)},scope:s});return c.onUnmounted((()=>{d()})),c.computed((()=>{let e=o.fn(f?p:p.value,r.value);return void 0!==e?e:o.defaultValue}))},exports.useUnit=o=>{const{scope:n}=t(),s=effector.is.unit(o);let r={};s?r={unit:o}:'@@unitShape'in o?'function'==typeof o['@@unitShape']?r=o['@@unitShape']():i('expect @@unitShape to be a function'):r=o;const a=Array.isArray(r),u=[],l=[];for(const e in r){const t=r[e];effector.is.unit(t)||i('expect useUnit argument to be a unit'),effector.is.event(t)||effector.is.effect(t)?l.push(e):u.push(e)}const f={};for(const t of u){const o=e(r[t],n),s=c.shallowRef(o),a=effector.createWatch({unit:r[t],fn:e=>{s.value=c.shallowRef(e).value},scope:n});f[t]={stop:a,ref:s}}if(c.onUnmounted((()=>{for(const e of Object.values(f))e.stop()})),s&&effector.is.store(o))return c.readonly(f.unit.ref);if(s&&effector.is.event(o))return effector.scopeBind(r.unit,{scope:n,safe:1});const p={};for(const e of l)p[e]=effector.scopeBind(r[e],{scope:n,safe:1});for(const[e,t]of Object.entries(f))p[e]=c.readonly(t.ref);return a?Object.values(p):p},exports.useVModel=(e,t)=>(t||c.effectScope()).run((()=>{const t=c.reactive({});if(effector.is.store(e))return n(e);const o=Object.fromEntries(Object.entries(e).map((([e,o])=>[e,n(o,e,t)])));for(const e in o)t[e]=o[e];return t}));
//# sourceMappingURL=composition.cjs.js.map

@@ -1,2 +0,2 @@

import {ComputedRef, DeepReadonly, Ref, UnwrapRef} from '@vue/reactivity'
import {ComputedRef, DeepReadonly, EffectScope, Reactive, Ref, UnwrapRef} from '@vue/reactivity'
import {Domain, Store, Event, Effect, Scope} from 'effector'

@@ -20,3 +20,3 @@

type ExtractStore<T extends Record<string, Store<unknown>>> = {
[Key in keyof T]: T[Key] extends Store<infer U> ? Ref<UnwrapRef<U>> : never
[Key in keyof T]: T[Key] extends Store<infer U> ? Reactive<U> : never
}

@@ -26,3 +26,3 @@

<T>(vm: Store<T>): Ref<T>
<T extends Record<string, Store<any>>>(vm: T): ExtractStore<T>
<T extends Record<string, Store<any>>>(vm: T, scope?: EffectScope): ExtractStore<T>
}

@@ -40,5 +40,6 @@

): ComputedRef<Result>
export function useVModel<T>(vm: Store<T>): Ref<UnwrapRef<T>>
export function useVModel<T>(vm: Store<T>, scope?: EffectScope): Ref<UnwrapRef<T>>
export function useVModel<T extends Record<string, Store<any>>>(
vm: T,
scope?: EffectScope
): ExtractStore<T>

@@ -45,0 +46,0 @@ export function useStore<T>(store: Store<T>): DeepReadonly<Ref<T>>

@@ -1,2 +0,2 @@

import {ComputedRef, DeepReadonly, Ref, UnwrapRef} from '@vue/reactivity'
import {ComputedRef, DeepReadonly, EffectScope, Reactive, Ref, UnwrapRef} from '@vue/reactivity'
import {Domain, Store, Event, Effect, Scope} from 'effector'

@@ -20,3 +20,3 @@

type ExtractStore<T extends Record<string, Store<unknown>>> = {
[Key in keyof T]: T[Key] extends Store<infer U> ? Ref<UnwrapRef<U>> : never
[Key in keyof T]: T[Key] extends Store<infer U> ? Reactive<U> : never
}

@@ -26,3 +26,3 @@

<T>(vm: Store<T>): Ref<T>
<T extends Record<string, Store<any>>>(vm: T): ExtractStore<T>
<T extends Record<string, Store<any>>>(vm: T, scope?: EffectScope): ExtractStore<T>
}

@@ -40,5 +40,6 @@

): ComputedRef<Result>
export function useVModel<T>(vm: Store<T>): Ref<UnwrapRef<T>>
export function useVModel<T>(vm: Store<T>, scope?: EffectScope): Ref<UnwrapRef<T>>
export function useVModel<T extends Record<string, Store<any>>>(
vm: T,
scope?: EffectScope
): ExtractStore<T>

@@ -45,0 +46,0 @@ export function useStore<T>(store: Store<T>): DeepReadonly<Ref<T>>

{
"name": "effector-vue",
"version": "23.0.0",
"version": "23.1.0",
"description": "Vue bindings for effector",

@@ -20,2 +20,8 @@ "main": "effector-vue.cjs.js",

},
"./options-vue3": {
"types": "./options-vue3.d.ts",
"import": "./options-vue3.mjs",
"require": "./options-vue3.cjs.js",
"default": "./options-vue3.mjs"
},
"./ssr": {

@@ -37,2 +43,7 @@ "types": "./ssr.d.ts",

},
"./options-vue3.mjs": {
"types": "./options-vue3.mjs.d.ts",
"import": "./options-vue3.mjs",
"default": "./options-vue3.mjs"
},
"./ssr.mjs": {

@@ -83,2 +94,4 @@ "types": "./ssr.mjs.d.ts",

"ssr.cjs.js.map",
"options-vue3.cjs.js",
"options-vue3.cjs.js.map",
"composition.mjs",

@@ -88,2 +101,4 @@ "composition.mjs.map",

"ssr.mjs.map",
"options-vue3.mjs",
"options-vue3.mjs.map",
"composition.d.ts",

@@ -94,3 +109,6 @@ "composition.mjs.d.ts",

"ssr.mjs.d.ts",
"ssr.cjs.d.ts"
"ssr.cjs.d.ts",
"options-vue3.d.ts",
"options-vue3.mjs.d.ts",
"options-vue3.cjs.d.ts"
],

@@ -97,0 +115,0 @@ "keywords": [

# effector-vue
Vue bindings for [effector](https://www.npmjs.com/package/effector)
## Installation
```bash
npm install --save effector effector-vue
```
Or using `yarn`
```bash
yarn add effector effector-vue
```
## Usage
```js
import {createStore, createEvent} from 'effector'
export const inputText = createEvent()
export const $text = createStore('').on(inputText, (_, text) => text)
export const $size = $text.map(text => text.length)
```
```html
<script lang="ts" setup>
import {useUnit} from 'effector-vue/composition'
import {$text, $size, inputText} from './model'
const text = useUnit($text)
const size = useUnit($size)
const handleTextChange = useUnit(inputText)
</script>
<template>
<form>
<input
type="text"
@input="(e) => handleTextChange(e.currentTarget.value)"
:value="text"
/>
<p>Length: {{ size }}</p>
</form>
</template>
```
[Try it](https://playcode.io/1914159)
[useUnit](https://effector.dev/docs/api/effector-react/useUnit) in docs
[Units](https://effector.dev/docs/glossary#unit) in docs
[createStore](https://effector.dev/docs/api/effector/createStore) in docs
[createEvent](https://effector.dev/docs/api/effector/createEvent) in docs

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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