Skip to content

Commit

Permalink
fix: move RegisteredAdapters to globak scope
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtek-krysiak committed Aug 7, 2020
1 parent b45da7d commit 0325a2a
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/admin-bro.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { OverridableComponent } from './frontend/utils/overridable-component'

describe('AdminBro', function () {
beforeEach(function () {
AdminBro.registeredAdapters = []
global.RegisteredAdapters = []
})

describe('#constructor', function () {
Expand All @@ -28,7 +28,7 @@ describe('AdminBro', function () {

it('adds given adapter to list off all available adapters', function () {
AdminBro.registerAdapter(this.DatabaseAdapter)
expect(AdminBro.registeredAdapters).to.have.lengthOf(1)
expect(global.RegisteredAdapters).to.have.lengthOf(1)
})

it('throws an error when adapter is not full', function () {
Expand Down
8 changes: 3 additions & 5 deletions src/admin-bro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ class AdminBro {

public translateFunctions!: TranslateFunctions

public static registeredAdapters: Array<Adapter>

/**
* Contains set of routes available within the application.
* It is used by external plugins.
Expand Down Expand Up @@ -182,7 +180,7 @@ class AdminBro {
this.initI18n()

const { databases, resources } = this.options
const resourcesFactory = new ResourcesFactory(this, AdminBro.registeredAdapters)
const resourcesFactory = new ResourcesFactory(this, global.RegisteredAdapters || [])
this.resources = resourcesFactory.buildResources({ databases, resources })
}

Expand Down Expand Up @@ -231,7 +229,8 @@ class AdminBro {
}
// checking if both Database and Resource have at least isAdapterFor method
if (Database.isAdapterFor && Resource.isAdapterFor) {
AdminBro.registeredAdapters.push({ Database, Resource })
global.RegisteredAdapters = global.RegisteredAdapters || []
global.RegisteredAdapters.push({ Database, Resource })
} else {
throw new Error('Adapter elements has to be a subclass of AdminBro.BaseResource and AdminBro.BaseDatabase')
}
Expand Down Expand Up @@ -365,7 +364,6 @@ class AdminBro {
}
}

AdminBro.registeredAdapters = []
AdminBro.VERSION = VERSION

// eslint-disable-next-line @typescript-eslint/no-empty-interface
Expand Down
1 change: 1 addition & 0 deletions vendor-types/node/node.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ type UserComponentsMap = {[key: string]: string}
declare namespace NodeJS {
interface Global {
UserComponents: UserComponentsMap | null;
RegisteredAdapters: Array<any> | null;
}
}
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# yarn lockfile v1


"@admin-bro/design-system@^1.3.2":
version "1.3.2"
resolved "https://registry.yarnpkg.com/@admin-bro/design-system/-/design-system-1.3.2.tgz#ec409d189b5112dd27f8ece974f2a7252c6db8c7"
integrity sha512-uwPiOLYgqlEwBnaCmKh0FXdhsDZ4HNIVkCBXzEW9U2SNcccZprYFYE0r2W5m7j2A9yVTPnAwKrwzrYjSGe0OBw==
"@admin-bro/design-system@^1.3.3":
version "1.3.3"
resolved "https://registry.yarnpkg.com/@admin-bro/design-system/-/design-system-1.3.3.tgz#a57d44988ec9501e7f199a49cad4f2b0180b9be1"
integrity sha512-sZ1ocow6pU5JuNA1mW4u8Sg82CEeT3jbD/GhSGzl4ct58A/iXC7uBoN6KvM/rqR+Fzk2T/EMh4ZCpEDh3Yp6Cw==
dependencies:
"@carbon/icons-react" "^10.14.0"
jw-paginate "^1.0.4"
Expand Down

0 comments on commit 0325a2a

Please sign in to comment.