Ver Fonte

update build setup

Evan You há 9 anos atrás
pai
commit
342e6fcdd1
8 ficheiros alterados com 13 adições e 116 exclusões
  1. 1 0
      .gitignore
  2. 3 2
      examples/shopping-cart/vuex/index.js
  3. 1 1
      examples/todomvc/vuex/middlewares.js
  4. 8 2
      package.json
  5. 0 38
      src/cursor.js
  6. 0 26
      src/index.js
  7. 0 47
      src/mixin.js
  8. 0 0
      webpack.config.js

+ 1 - 0
.gitignore

@@ -1,3 +1,4 @@
 .DS_Store
 node_modules
 TODO.md
+lib

+ 3 - 2
examples/shopping-cart/vuex/index.js

@@ -1,5 +1,6 @@
 import Vue from 'vue'
-import Vuex, { loggerMiddleware } from '../../../src'
+import Vuex from '../../../src'
+import logger from '../../../src/middlewares/logger'
 import * as actions from './actions'
 import { cartInitialState, cartMutations } from './stores/cart'
 import { productsInitialState, productsMutations } from './stores/products'
@@ -14,5 +15,5 @@ export default new Vuex({
   },
   actions,
   mutations: [cartMutations, productsMutations],
-  middlewares: [loggerMiddleware]
+  middlewares: [logger]
 })

+ 1 - 1
examples/todomvc/vuex/middlewares.js

@@ -1,5 +1,5 @@
 import { STORAGE_KEY } from './index'
-import { loggerMiddleware } from '../../../src'
+import loggerMiddleware from '../../../src/middlewares/logger'
 
 const localStorageMiddleware = {
   onMutation (mutation, { todos }) {

+ 8 - 2
package.json

@@ -2,11 +2,16 @@
   "name": "vuex",
   "version": "1.0.0",
   "description": "state management for Vue.js",
-  "main": "src/index.js",
+  "main": "lib/index.js",
+  "files": [
+    "lib",
+    "src"
+  ],
   "scripts": {
     "dev-counter": "cd examples/counter && webpack-dev-server --inline --hot --config ../webpack.shared.config.js",
     "dev-todomvc": "cd examples/todomvc && webpack-dev-server --inline --hot --config ../webpack.shared.config.js",
-    "dev-cart": "cd examples/shopping-cart && webpack-dev-server --inline --hot --config ../webpack.shared.config.js"
+    "dev-cart": "cd examples/shopping-cart && webpack-dev-server --inline --hot --config ../webpack.shared.config.js",
+    "prepublish": "babel src --out-dir lib --presets es2015 --plugins add-module-exports"
   },
   "repository": {
     "type": "git",
@@ -21,6 +26,7 @@
   "devDependencies": {
     "babel-core": "^6.2.1",
     "babel-loader": "^6.2.0",
+    "babel-plugin-add-module-exports": "^0.1.1",
     "babel-plugin-transform-runtime": "^6.1.18",
     "babel-polyfill": "^6.2.0",
     "babel-preset-es2015": "^6.1.18",

+ 0 - 38
src/cursor.js

@@ -1,38 +0,0 @@
-export default class Cursor {
-
-  /**
-   * @param {Vue} vm
-   * @param {String} path
-   */
-
-  constructor (vm, path) {
-    this.cb = null
-    this.vm = vm
-    this.path = path
-    this.dispose = vm.$watch(path, value => {
-      if (this.cb) {
-        this.cb.call(null, value)
-      }
-    })
-  }
-
-  /**
-   * Get the latest value.
-   *
-   * @return {*}
-   */
-
-  get () {
-    return this.vm.$get(this.path)
-  }
-
-  /**
-   * Set the subscribe callback.
-   *
-   * @param {Function} cb
-   */
-
-  subscribe (cb) {
-    this.cb = cb
-  }
-}

+ 0 - 26
src/index.js

@@ -1,11 +1,7 @@
-import mixin from './mixin'
-import Cursor from './cursor'
 import devtoolMiddleware from './middlewares/devtool'
-import loggerMiddleware from './middlewares/logger'
 
 let Vue
 
-export { loggerMiddleware }
 export default class Vuex {
 
   /**
@@ -56,19 +52,6 @@ export default class Vuex {
     })
   }
 
-  /**
-   * "Get" the store's state, or a part of it.
-   * Returns a Cursor, which can be subscribed to for change,
-   * and disposed of when no longer needed.
-   *
-   * @param {String} [path]
-   * @return {Cursor}
-   */
-
-  get (path) {
-    return new Cursor(this._vm, path)
-  }
-
   /**
    * Dispatch an action.
    *
@@ -113,14 +96,6 @@ export default class Vuex {
   get state () {
     return this._vm._data
   }
-
-  /**
-   * Expose the logger middleware
-   */
-
-  static get loggerMiddleware () {
-    return loggerMiddleware
-  }
 }
 
 /**
@@ -129,7 +104,6 @@ export default class Vuex {
 
 Vuex.install = function (_Vue) {
   Vue = _Vue
-  Vue.mixin(mixin)
 }
 
 /**

+ 0 - 47
src/mixin.js

@@ -1,47 +0,0 @@
-import Cursor from './cursor'
-
-export default {
-
-  /**
-   * Patch the instance's data function so that we can
-   * directly bind to cursors in the `data` option.
-   */
-
-  init () {
-    const dataFn = this.$options.data
-    if (dataFn) {
-      this.$options.data = () => {
-        const raw = dataFn()
-        Object.keys(raw).forEach(key => {
-          const val = raw[key]
-          if (val instanceof Cursor) {
-            raw[key] = val.get()
-            if (val.cb) {
-              throw new Error(
-                '[vue-store] A vue-store can only be subscribed to once.'
-              )
-            }
-            val.subscribe(value => {
-              this[key] = value
-            })
-            if (!this._vue_store_cursors) {
-              this._vue_store_cursors = []
-            }
-            this._vue_store_cursors.push(val)
-          }
-        })
-        return raw
-      }
-    }
-  },
-
-  /**
-   * Dispose cursors owned by this instance.
-   */
-
-  beforeDestroy () {
-    if (this._vue_store_cursors) {
-      this._vue_store_cursors.forEach(c => c.dispose())
-    }
-  }
-}

+ 0 - 0
webpack.config.js