Skip to content

Commit

Permalink
Merge pull request #3 from davestewart/fix/0002-global-state
Browse files Browse the repository at this point in the history
Revert to previous prototype walk algorithm
  • Loading branch information
davestewart committed May 21, 2020
2 parents 3857869 + b2bf8db commit d532839
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "vue-class-store",
"description": "Universal Vue stores you write once and use anywhere",
"version": "2.0.3",
"version": "2.0.4",
"author": "Dave Stewart",
"license": "MIT",
"main": "dist/vue-class-store.js",
Expand Down
21 changes: 10 additions & 11 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
import Vue, { ComponentOptions, VueConstructor } from 'vue'
import Vue, { ComponentOptions } from 'vue'

type C = { new (...args: any[]): {} }

type R = Record<any, any>

function getDescriptors (model: R) {
export function makeOptions(model: R): ComponentOptions<any> {
// prototype
const prototype = Object.getPrototypeOf(model)
if (prototype === null || prototype === Object.prototype) {
if (!prototype || prototype === Object.prototype) {
return {}
}
const prototypeDescriptors = getDescriptors(prototype)
const descriptors = Object.getOwnPropertyDescriptors(prototype)
return { ...prototypeDescriptors, ...descriptors }
}

export function makeOptions(model: R): ComponentOptions<any> {
// prototype
const prototype = Object.getPrototypeOf(model)
const descriptors = getDescriptors(prototype)
// parent options
const extendsOptions = makeOptions(prototype)

// descriptors
const descriptors = Object.getOwnPropertyDescriptors(prototype)

// options
const name = prototype.constructor.name
Expand Down Expand Up @@ -59,6 +57,7 @@ export function makeOptions(model: R): ComponentOptions<any> {
// return
return {
name,
extends: extendsOptions,
computed,
methods,
watch,
Expand Down

0 comments on commit d532839

Please sign in to comment.