Skip to content

Commit

Permalink
vue 2.2 support, esm build closes #41
Browse files Browse the repository at this point in the history
  • Loading branch information
t2t2 committed Mar 5, 2017
1 parent edd8ce2 commit a061b63
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 38 deletions.
16 changes: 3 additions & 13 deletions example/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,20 @@ module.exports = {
publicPath: '/'
},
module: {
loaders: [
rules: [
{
test: /\.vue$/,
loader: 'vue'
},
{ // Needed for feathers/client
test: /\.json$/,
loader: 'json'
use: 'vue-loader'
},
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel',
query: {
presets: ['latest'],
plugins: ['transform-runtime']
}
use: 'babel-loader'
}
]
},
plugins: [
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin(),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: '"development"'
Expand Down
7 changes: 4 additions & 3 deletions jsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
// for the documentation about the jsconfig.json format
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"allowSyntheticDefaultImports": true
"allowSyntheticDefaultImports": true,
"experimentalDecorators": true
},
"exclude": [
"/node_modules/"
"node_modules",
"dist"
]
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"scripts": {
"build": "npm-run-all clean:dist build:*",
"build:commonjs": "rollup -c",
"build:esm": "rollup -c",
"ci:test": "npm-run-all lint coverage",
"clean": "npm-run-all clean:*",
"clean:dist": "rimraf dist/*.*",
Expand Down Expand Up @@ -75,7 +76,7 @@
"vue-loader": "^11.0.0",
"vue-style-loader": "^2.0.0",
"vue-template-compiler": "^2.1.8",
"webpack": "^1.14.0",
"webpack": "^2.2.1",
"webpack-dev-middleware": "^1.9.0",
"webpack-hot-middleware": "^2.14.0",
"xo": "^0.17.1"
Expand Down
25 changes: 14 additions & 11 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,33 @@ const config = {
'feathers-commons/lib/utils',
'feathers-query-filters'
],
format: 'cjs',
plugins: [
babel({
presets: [
[
'latest',
{
es2015: {
modules: false
}
}
]
['env', {
targets: {
browsers: '> 1%, Last 2 versions, IE 9' // Based on vue's requirements
},
modules: false,
loose: true
}]
],
plugins: [
'external-helpers'
],
babelrc: false
})
],
dest: path.join(__dirname, '/dist/vue-syncers-feathers.common.js')
]
}

if (process.env.npm_lifecycle_event === 'build:commonjs') {
// Common.js build
config.format = 'cjs'
config.dest = path.join(__dirname, '/dist/vue-syncers-feathers.common.js')
} else if (process.env.npm_lifecycle_event === 'build:esm') {
// Common.js build
config.format = 'es'
config.dest = path.join(__dirname, '/dist/vue-syncers-feathers.esm.js')
}

export default config
4 changes: 2 additions & 2 deletions src/syncers/collection.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {pick} from '../utils'
import {looseEqual, pick} from '../utils'
import BaseSyncer from './base'

/**
Expand Down Expand Up @@ -71,7 +71,7 @@ export default class CollectionSyncer extends BaseSyncer {
// When new value is found
const callback = function (newVal) {
// Avoid re-querying if it's the same
if (this.Vue.util.looseEqual(this.filters.query, newVal)) {
if (looseEqual(this.filters.query, newVal)) {
this.filters.query = newVal
return
}
Expand Down
36 changes: 36 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,39 @@ export function pick(source, ...keys) {
}
return result
}

/**
* Check if object is JSONable
*
* @from https://github.com/vuejs/vue/blob/0b902e0c28f4f324ffb8efbc9db74127430f8a42/src/shared/util.js#L155
* @param {*} obj
* @returns {boolean}
*/
function isObject(obj) {
return obj !== null && typeof obj === 'object'
}

/**
* Loosely check if objects are equal
*
* @from https://github.com/vuejs/vue/blob/0b902e0c28f4f324ffb8efbc9db74127430f8a42/src/shared/util.js
* @param {*} a
* @param {*} b
* @returns {boolean}
*/
export function looseEqual(a, b) {
const isObjectA = isObject(a)
const isObjectB = isObject(b)
if (isObjectA && isObjectB) {
try {
return JSON.stringify(a) === JSON.stringify(b)
} catch (err) {
// possible circular reference
return a === b
}
} else if (!isObjectA && !isObjectB) {
return String(a) === String(b)
} else {
return false
}
}
2 changes: 1 addition & 1 deletion test/collection.query.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ test('Switching queries', async t => {
// Null query: just cleared
await new Promise(resolve => {
instance.variables.query = null
Vue.util.nextTick(() => {
Vue.nextTick(() => {
resolve()
})
})
Expand Down
8 changes: 4 additions & 4 deletions test/core.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ test.cb('Syncer lifecycle methods are called in right order', t => {
// no ready in node mode
t.is(order++, 3, 'Vue instance is ready')

Vue.util.nextTick(function () {
Vue.nextTick(function () {
instance.$destroy()
})
},
Expand All @@ -70,11 +70,11 @@ test.cb('Syncer lifecycle methods are called in right order', t => {
destroyed: function () {
t.is(order++, 6, 'Vue instance is destroyed')

Vue.util.nextTick(function () {
Vue.nextTick(function () {
// Make sure hook doesn't cause double cleanup for any weird reason
instance.$destroy()

Vue.util.nextTick(function () {
Vue.nextTick(function () {
t.end()
})
})
Expand All @@ -95,7 +95,7 @@ test.cb('Non-used instances work fine', t => {
destroyed: function () {
t.pass()

Vue.util.nextTick(function () {
Vue.nextTick(function () {
t.end()
})
}
Expand Down
Empty file added test/helpers/util.js
Empty file.
4 changes: 2 additions & 2 deletions test/integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ test.cb('Cleanup', t => {
},
created() {
this.$on('syncer-loaded', () => {
Vue.util.nextTick(() => {
Vue.nextTick(() => {
instance.$destroy()
})
})
Expand Down Expand Up @@ -84,7 +84,7 @@ test.cb('Synced key can\'t be directly overwritten', t => {
},
created() {
this.$on('syncer-loaded', () => {
Vue.util.nextTick(() => {
Vue.nextTick(() => {
this.test = 'Failed'

t.not(this.test, 'Failed')
Expand Down
2 changes: 1 addition & 1 deletion test/item.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ test('Switching items', async t => {
// Test null id (should just clear the target)
await new Promise(resolve => {
instance.variables.itemId = null
Vue.util.nextTick(() => {
Vue.nextTick(() => {
resolve()
})
})
Expand Down

0 comments on commit a061b63

Please sign in to comment.