Skip to content

Commit

Permalink
Issue kaorun343#249: Remerge of PR kaorun343#299.
Browse files Browse the repository at this point in the history
  • Loading branch information
gmoneh committed Jun 16, 2020
2 parents 365cf55 + 3730103 commit 8c77f01
Show file tree
Hide file tree
Showing 8 changed files with 185 additions and 50 deletions.
38 changes: 38 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: ''
assignees: ''

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Desktop (please complete the following information):**
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]

**Smartphone (please complete the following information):**
- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]

**Additional context**
Add any other context about the problem here.
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: ''
assignees: ''

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Changelog

# v8.5.0

- Revert #299
- Add CHANGELOG.md
- Fix README.md (#319)
- Move `vue-class-component` to `peerDependencies`
64 changes: 32 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ is equivalent to
export default {
props: {
propA: {
type: Number
type: Number,
},
propB: {
default: 'default value'
default: 'default value',
},
propC: {
type: [String, Boolean]
}
}
type: [String, Boolean],
},
},
}
```

Expand Down Expand Up @@ -105,8 +105,8 @@ is equivalent to
export default {
props: {
name: {
type: String
}
type: String,
},
},
computed: {
syncedName: {
Expand All @@ -115,9 +115,9 @@ export default {
},
set(value) {
this.$emit('update:name', value)
}
}
}
},
},
},
}
```

Expand All @@ -140,13 +140,13 @@ is equivalent to
export default {
model: {
prop: 'checked',
event: 'change'
event: 'change',
},
props: {
checked: {
type: Boolean
}
}
type: Boolean,
},
},
}
```

Expand Down Expand Up @@ -179,27 +179,27 @@ export default {
{
handler: 'onChildChanged',
immediate: false,
deep: false
}
deep: false,
},
],
person: [
{
handler: 'onPersonChanged1',
immediate: true,
deep: true
deep: true,
},
{
handler: 'onPersonChanged2',
immediate: false,
deep: false
}
]
deep: false,
},
],
},
methods: {
onChildChanged(val, oldVal) {},
onPersonChanged1(val, oldVal) {},
onPersonChanged2(val, oldVal) {}
}
onPersonChanged2(val, oldVal) {},
},
}
```

Expand Down Expand Up @@ -232,20 +232,20 @@ export const MyComponent = Vue.extend({
foo: 'foo',
bar: 'bar',
optional: { from: 'optional', default: 'default' },
[symbol]: symbol
baz: symbol,
},
data() {
return {
foo: 'foo',
baz: 'bar'
baz: 'bar',
}
},
provide() {
return {
foo: this.foo,
bar: this.baz
bar: this.baz,
}
}
},
})
```

Expand Down Expand Up @@ -303,7 +303,7 @@ export default class YourComponent extends Vue {

@Emit()
promise() {
return new Promise(resolve => {
return new Promise((resolve) => {
setTimeout(() => {
resolve(20)
}, 0)
Expand All @@ -318,7 +318,7 @@ is equivalent to
export default {
data() {
return {
count: 0
count: 0,
}
},
methods: {
Expand All @@ -337,17 +337,17 @@ export default {
this.$emit('on-input-change', e.target.value, e)
},
promise() {
const promise = new Promise(resolve => {
const promise = new Promise((resolve) => {
setTimeout(() => {
resolve(20)
}, 0)
})

promise.then(value => {
promise.then((value) => {
this.$emit('promise', value)
})
}
}
},
},
}
```

Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vue-property-decorator",
"version": "8.4.1",
"version": "8.5.0",
"description": "property decorators for Vue Component",
"main": "lib/vue-property-decorator.umd.js",
"module": "lib/vue-property-decorator.js",
Expand Down Expand Up @@ -29,14 +29,14 @@
"rollup": "^1.15.6",
"ts-jest": "^24.0.2",
"typescript": "^3.5.2",
"vue": "^2.6.10"
"vue": "^2.6.10",
"vue-class-component": "^7.2.3"
},
"typings": "./lib/vue-property-decorator.d.ts",
"dependencies": {
"vue-class-component": "^7.1.0"
},
"dependencies": {},
"peerDependencies": {
"vue": "*"
"vue": "*",
"vue-class-component": "*"
},
"repository": {
"type": "git",
Expand Down
14 changes: 6 additions & 8 deletions src/vue-property-decorator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/** vue-property-decorator verson 8.4.1 MIT LICENSE copyright 2019 kaorun343 */
/** vue-property-decorator verson 8.5.0 MIT LICENSE copyright 2020 kaorun343 */
/// <reference types='reflect-metadata'/>
'use strict'
import Vue, { PropOptions, WatchOptions } from 'vue'
Expand Down Expand Up @@ -46,7 +46,7 @@ export function InjectReactive(options?: InjectOptions | InjectKey) {
const fromKey = !!options ? (options as any).from || options : key
const defaultVal = (!!options && (options as any).default) || undefined
if (!componentOptions.computed) componentOptions.computed = {}
componentOptions.computed![key] = function() {
componentOptions.computed![key] = function () {
const obj = (this as any)[reactiveInjectKey]
return obj ? obj[fromKey] : defaultVal
}
Expand All @@ -62,7 +62,7 @@ interface provideObj {
type provideFunc = ((this: any) => Object) & provideObj

function produceProvide(original: any) {
let provide: provideFunc = function(this: any) {
let provide: provideFunc = function (this: any) {
let rv = typeof original === 'function' ? original.call(this) : original
rv = Object.create(rv || null)
// set reactive services (propagates previous services if necessary)
Expand Down Expand Up @@ -264,7 +264,7 @@ const hyphenate = (str: string) => str.replace(hyphenateRE, '-$1').toLowerCase()
* @return MethodDecorator
*/
export function Emit(event?: string) {
return function(_target: Vue, propertyKey: string, descriptor: any) {
return function (_target: Vue, propertyKey: string, descriptor: any) {
const key = hyphenate(propertyKey)
const original = descriptor.value
descriptor.value = function emitter(...args: any[]) {
Expand All @@ -277,7 +277,7 @@ export function Emit(event?: string) {
} else if (args.length === 1) {
this.$emit(emitName, args[0])
} else {
this.$emit(emitName, args)
this.$emit(emitName, ...args)
}
} else {
args.unshift(returnValue);
Expand All @@ -288,9 +288,7 @@ export function Emit(event?: string) {
const returnValue: any = original.apply(this, args)

if (isPromise(returnValue)) {
returnValue.then(returnValue => {
emit(returnValue)
})
returnValue.then(emit)
} else {
emit(returnValue)
}
Expand Down
71 changes: 71 additions & 0 deletions tests/Emit.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,77 @@ describe(Emit, () => {
expect(mockFn.mock.calls[0][1]).toBe(value)
})
})

describe('when multiple arguments is given', () => {
@Component
class ChildComponent extends Vue {
count = 0

@Emit() increment(n1: number, n2: number) {
this.count += n1 + n2
}
}

const child = new ChildComponent()
const mockFn = jest.fn()
child.$emit = mockFn

const value1 = 30
const value2 = 40

beforeAll(() => {
child.increment(value1, value2)
})

test('call $emit method', () => {
expect(mockFn).toHaveBeenCalled()
})

test('emit event with method name', () => {
expect(mockFn.mock.calls[0][0]).toBe('increment')
})

test('emit event with multiple arguments', () => {
expect(mockFn.mock.calls[0][1]).toBe(value1)
expect(mockFn.mock.calls[0][2]).toBe(value2)
})
})

describe('when the value is returned and multiple arguments is given', () => {
@Component
class ChildComponent extends Vue {
count = 0

@Emit() increment(n1: number, n2: number) {
return n1 + n2;
}
}

const child = new ChildComponent()
const mockFn = jest.fn()
child.$emit = mockFn

const value1 = 30
const value2 = 40

beforeAll(() => {
child.increment(value1, value2)
})

test('call $emit method', () => {
expect(mockFn).toHaveBeenCalled()
})

test('emit event with method name', () => {
expect(mockFn.mock.calls[0][0]).toBe('increment')
})

test('emit event with multiple arguments', () => {
expect(mockFn.mock.calls[0][1]).toBe(value1 + value2)
expect(mockFn.mock.calls[0][2]).toBe(value1)
expect(mockFn.mock.calls[0][3]).toBe(value2)
})
})

describe('when promise has been returned', () => {
const value = 10
Expand Down
Loading

0 comments on commit 8c77f01

Please sign in to comment.