Repository: effector/effector
Pull request #484 (2021-04-30 00:35:40)

fix types in effector-vue composition


Patch:
diff --git a/.eslintrc b/.eslintrc
index 8e5d79c5..fdf2d59e 100644
--- a/.eslintrc
+++ b/.eslintrc
@@ -2,13 +2,13 @@ parser: '@babel/eslint-parser'
 parserOptions:
   ecmaVersion: 2018
 extends:
-- plugin:react/recommended
-- prettier
+  - 'plugin:react/recommended'
+  - prettier
 plugins:
-- babel
-- jest
-- react
-- react-hooks
+  - babel
+  - jest
+  - react
+  - react-hooks
 settings:
   react:
     version: '16.13'
@@ -21,78 +21,79 @@ env:
   jasmine: true
 rules:
   react-hooks/rules-of-hooks: error
-  react/react-in-jsx-scope: off
-  react/no-children-prop: off
-  react/prop-types: off
-  react/display-name: off
-  react/jsx-key: off
-  react/no-unknown-property: off
-  no-console: off
+  react/react-in-jsx-scope: 'off'
+  react/no-children-prop: 'off'
+  react/prop-types: 'off'
+  react/display-name: 'off'
+  react/jsx-key: 'off'
+  react/no-unknown-property: 'off'
+  no-console: 'off'
   no-cond-assign: warn
   no-unused-vars: warn
-  prefer-template: off
-  no-nested-ternary: off
+  prefer-template: 'off'
+  no-nested-ternary: 'off'
   no-unneeded-ternary: warn
   no-underscore-dangle: off
   prefer-const: warn
-  no-unused-labels: off
+  no-unused-labels: 'off'
   no-extra-bind: error
   no-case-declarations: error
   no-useless-call: error
   prefer-arrow-callback:
-  - error
-  - allowNamedFunctions: true
-  object-shorthand: off
-  no-extra-parens: off
-  multiline-ternary: off
+    - error
+    - allowNamedFunctions: true
+  object-shorthand:
+    - off
+  no-extra-parens: 'off'
+  multiline-ternary: 'off'
   arrow-body-style:
-  - error
-  - as-needed
+    - error
+    - as-needed
   no-var: error
-  no-duplicate-imports: off
+  no-duplicate-imports: 'off'
   quotes:
-  - error
-  - single
-  - allowTemplateLiterals: true
-    avoidEscape: true
+    - error
+    - single
+    - allowTemplateLiterals: true
+      avoidEscape: true
   key-spacing:
-  - warn
-  - beforeColon: false
-    afterColon: true
-    mode: strict
+    - warn
+    - beforeColon: false
+      afterColon: true
+      mode: strict
   comma-spacing:
-  - error
-  - before: false
-    after: true
+    - error
+    - before: false
+      after: true
   block-spacing:
-  - error
-  - never
+    - error
+    - never
   object-curly-spacing:
-  - warn
-  - never
+    - warn
+    - never
   semi-spacing:
-  - error
-  - before: false
-    after: true
+    - error
+    - before: false
+      after: true
   indent: off
   newline-per-chained-call:
-  - error
+    - error
   keyword-spacing:
-  - error
+    - error
   space-unary-ops:
-  - error
-  - words: true
-    nonwords: false
+    - error
+    - words: true
+      nonwords: false
   no-whitespace-before-property: error
   arrow-spacing:
-  - error
-  - before: true
-    after: true
+    - error
+    - before: true
+      after: true
   space-before-function-paren:
-  - false
+    - off
   rest-spread-spacing:
-  - error
-  - never
+    - error
+    - never
   no-alert: error
   no-bitwise: 0
   no-caller: error
@@ -101,21 +102,21 @@ rules:
   no-implied-eval: error
   no-proto: error
   no-iterator: error
-  no-lone-blocks: off
+  no-lone-blocks: 'off'
   no-self-compare: error
   no-self-assign:
-  - error
-  - props: true
+    - error
+    - props: true
   no-invalid-regexp:
-  - error
-  - allowConstructorFlags:
-    - u
-    - y
+    - error
+    - allowConstructorFlags:
+        - u
+        - 'y'
   no-with: error
   no-new-func: error
   prefer-rest-params: error
   prefer-spread: error
   no-extra-semi: off
   semi:
-  - error
-  - never
\ No newline at end of file
+    - error
+    - never
diff --git a/packages/effector-vue/composition.d.ts b/packages/effector-vue/composition.d.ts
index 27ebcb14..9be6fa65 100644
--- a/packages/effector-vue/composition.d.ts
+++ b/packages/effector-vue/composition.d.ts
@@ -1,8 +1,6 @@
 import {DeepReadonly, Ref, UnwrapRef} from '@vue/reactivity'
 import {Domain, Store, Event} from 'effector'
 
-type UnwrapNestedRefs<T> = T extends Ref ? T : UnwrapRef<T>
-
 type GateConfig<T> = {
   name?: string;
   defaultState?: T;
@@ -17,7 +15,7 @@ type Gate<Props> = {
   set: Event<Props>;
 };
 
-export function useStore<T>(store: Store<T>): DeepReadonly<UnwrapNestedRefs<T>>
+export function useStore<T>(store: Store<T>): DeepReadonly<Ref<T>>
 export function useVModel<T>(store: Store<T>): Ref<UnwrapRef<T>>
 export function createGate<Props>(config?: GateConfig<Props>): Gate<Props>
 export function useGate<Props>(GateComponent: Gate<Props>, cb?: () => Props): void
\ No newline at end of file
diff --git a/src/babel/babel-plugin.js b/src/babel/babel-plugin.js
index f1c4d671..d4eebcad 100644
--- a/src/babel/babel-plugin.js
+++ b/src/babel/babel-plugin.js
@@ -169,12 +169,9 @@ module.exports = function(babel, options = {}) {
           if (!this.effector_factoryMap) {
             this.effector_factoryMap = new Map()
             if (!factoryTemplate) {
-              let tpl
               factoryTemplate = template(
                 addLoc
                   ? 'withFactory({sid: SID,fn:()=>FN,name:NAME,method:METHOD,loc:LOC})'
-                  : addNames
-                  ? 'withFactory({sid: SID,fn:()=>FN,name:NAME,method:METHOD})'
                   : 'withFactory({sid: SID,fn:()=>FN})',
               )
             }
@@ -395,13 +392,11 @@ module.exports = function(babel, options = {}) {
               SID: JSON.stringify(sid),
               FN: path.node,
             }
-            if (addLoc || addNames) {
+            if (addLoc) {
               factoryConfig.NAME = JSON.stringify(
                 !resultName || resultName === '' ? 'none' : resultName,
               )
               factoryConfig.METHOD = JSON.stringify(importedName)
-            }
-            if (addLoc) {
               factoryConfig.LOC = makeTrace(
                 state.fileNameIdentifier,
                 loc.line,
diff --git a/src/vue/lib/deepCopy.ts b/src/vue/lib/deepCopy.ts
index b54eb5fb..9ca61213 100644
--- a/src/vue/lib/deepCopy.ts
+++ b/src/vue/lib/deepCopy.ts
@@ -3,7 +3,7 @@ function find(list, f) {
   return list.filter(f)[0]
 }
 
-export function deepCopy(obj, cache = []) {
+export function deepCopy<T>(obj, cache = []): T {
   if (obj === null || typeof obj !== 'object') {
     return obj
   }
diff --git a/src/vue/useVModel.ts b/src/vue/useVModel.ts
index 271874a7..e0e979b5 100644
--- a/src/vue/useVModel.ts
+++ b/src/vue/useVModel.ts
@@ -9,9 +9,8 @@ export function useVModel<T>(store: Store<T>) {
 
   let isSelfUpdate = false
   let fromEvent = false
-  let unwatch: Subscription
 
-  unwatch = store.updates.watch(payload => {
+  const unwatch = store.updates.watch(payload => {
     if (isSelfUpdate) {
       return
     }
diff --git a/website/client/src/pages/styles.module.css b/website/client/src/pages/styles.module.css
index 1a235be1..87f26d1e 100644
--- a/website/client/src/pages/styles.module.css
+++ b/website/client/src/pages/styles.module.css
@@ -65,7 +65,6 @@ header[data-section-header] {
 
 .features > [data-features-grid] {
   grid-row: 2;
-  margin: 0;
 }
 
 .features [data-feature-image] {


Test patch:
diff --git a/src/babel/__tests__/__snapshots__/babel-plugin.test.js.snap b/src/babel/__tests__/__snapshots__/babel-plugin.test.js.snap
index d4f5741a..f825c062 100644
--- a/src/babel/__tests__/__snapshots__/babel-plugin.test.js.snap
+++ b/src/babel/__tests__/__snapshots__/babel-plugin.test.js.snap
@@ -1379,57 +1379,6 @@ const g2_val = g2(0)
 "
 `;
 
-exports[`babel-plugin should factories only with name with options 1`] = `
-"import {withFactory} from 'effector'
-import {itIsALongName, Randomizing} from 'c/d'
-import Defaulting, {AnotherImport} from '@/f'
-import {splitMap} from 'patronum/split-map'
-const longer = withFactory({
-  sid: 'sxdi9p',
-  fn: () => itIsALongName(0),
-  name: 'longer',
-  method: 'itIsALongName',
-})
-const arcade = withFactory({
-  sid: '-rwb2il',
-  fn: () =>
-    Defaulting({
-      source: longer,
-      condition: withFactory({
-        sid: '-6rcqb6',
-        fn: () =>
-          AnotherImport({
-            test: true,
-          }),
-        name: 'condition',
-        method: 'AnotherImport',
-      }),
-    }),
-  name: 'arcade',
-  method: 'default',
-})
-withFactory({
-  sid: '-dr78v0',
-  fn: () =>
-    Randomizing({
-      arcade,
-    }),
-  name: 'none',
-  method: 'Randomizing',
-})
-const result = withFactory({
-  sid: '-fbu55p',
-  fn: () =>
-    splitMap({
-      longer,
-      source: arcade,
-    }),
-  name: 'result',
-  method: 'splitMap',
-})
-"
-`;
-
 exports[`babel-plugin should factories without name with options 1`] = `
 "import {withFactory} from 'effector'
 import {itIsALongName, Randomizing} from 'c/d'
diff --git a/src/babel/__tests__/fixtures/factories-only-with-name.js b/src/babel/__tests__/fixtures/factories-only-with-name.js
deleted file mode 100644
index cbbf69a0..00000000
--- a/src/babel/__tests__/fixtures/factories-only-with-name.js
+++ /dev/null
@@ -1,15 +0,0 @@
-import {itIsALongName, Randomizing} from 'c/d'
-import Defaulting, {AnotherImport} from '@/f'
-import {splitMap} from 'patronum/split-map'
-
-const longer = itIsALongName(0)
-const arcade = Defaulting({
-  source: longer,
-  condition: AnotherImport({test: true}),
-})
-Randomizing({arcade})
-
-const result = splitMap({
-  longer,
-  source: arcade,
-})
diff --git a/src/babel/__tests__/fixtures/factories-only-with-name.options.json b/src/babel/__tests__/fixtures/factories-only-with-name.options.json
deleted file mode 100644
index 13cda5b6..00000000
--- a/src/babel/__tests__/fixtures/factories-only-with-name.options.json
+++ /dev/null
@@ -1,5 +0,0 @@
-{
-  "factories": ["c/d", "@/f", "patronum/split-map"],
-  "addNames": true,
-  "addLoc": false
-}