Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate getType #899

Merged
merged 5 commits into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/effector/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ export interface Event<Payload> extends Unit<Payload> {
* @deprecated use js pipe instead
*/
thru<U>(fn: (event: Event<Payload>) => U): U
/**
* @deprecated use .compositeName.fullName instead
*/
getType(): string
compositeName: CompositeName
sid: string | null
Expand Down Expand Up @@ -188,6 +191,9 @@ export interface Effect<Params, Done, Fail = Error> extends Unit<Params> {
map<T>(fn: (params: Params) => T): EventAsReturnType<T>
prepend<Before>(fn: (_: Before) => Params): Event<Before>
subscribe(observer: Observer<Params>): Subscription
/**
* @deprecated use .compositeName.fullName instead
*/
getType(): string
compositeName: CompositeName
sid: string | null
Expand Down Expand Up @@ -344,6 +350,9 @@ export class Domain implements Unit<any> {
sid: string | null
compositeName: CompositeName
shortName: string
/**
* @deprecated use .compositeName.fullName instead
*/
getType(): string
history: {
domains: Set<Domain>
Expand Down
13 changes: 13 additions & 0 deletions src/effector/__tests__/domain.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@ import {
} from 'effector'
import {argumentHistory} from 'effector/fixtures'

const originalConsoleError = console.error

beforeAll(() => {
console.error = (message, ...args) => {
if (String(message).includes('getType')) return
originalConsoleError(message, ...args)
}
})

afterAll(() => {
console.error = originalConsoleError
})

describe('domain hooks', () => {
test('domain.onCreateEvent(fn)', () => {
const fn = jest.fn()
Expand Down
13 changes: 13 additions & 0 deletions src/effector/__tests__/effect/name.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
import {createEffect, createDomain} from 'effector'

const originalConsoleError = console.error

beforeAll(() => {
console.error = (message, ...args) => {
if (String(message).includes('getType')) return
originalConsoleError(message, ...args)
}
})

afterAll(() => {
console.error = originalConsoleError
})

test("should return it's own name on effect.getType()", () => {
expect(createEffect('foo').getType()).toBe('foo')
expect(createEffect('foo', {name: 'bar'}).getType()).toBe('foo')
Expand Down
13 changes: 13 additions & 0 deletions src/effector/__tests__/event/name.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
import {createEvent, createDomain} from 'effector'

const originalConsoleError = console.error

beforeAll(() => {
console.error = (message, ...args) => {
if (String(message).includes('getType')) return
originalConsoleError(message, ...args)
}
})

afterAll(() => {
console.error = originalConsoleError
})

test("should return it's own name on event.getType()", () => {
expect(createEvent('foo').getType()).toBe('foo')
expect(createEvent({name: 'foo'}).getType()).toBe('foo')
Expand Down
19 changes: 19 additions & 0 deletions src/effector/__tests__/naming.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {createEvent, createStore, createDomain, combine, sample} from 'effector'
import {argumentHistory} from 'effector/fixtures'
import {unitObjectName} from '../naming'

const rootDomain = createDomain('')
Expand Down Expand Up @@ -114,3 +115,21 @@ describe('sample support', () => {
expect(sampled.shortName).toBe('foo')
})
})

describe('getType deprecation', () => {
const fn = jest.fn()
const originalConsoleError = console.error
beforeEach(() => {
console.error = fn
})
afterEach(() => {
console.error = originalConsoleError
})
test('getType deprecation', () => {
const event = createEvent()
event.getType()
expect(argumentHistory(fn)[0]).toMatchInlineSnapshot(
`"getType is deprecated, use compositeName.fullName instead"`,
)
})
})
6 changes: 5 additions & 1 deletion src/effector/createEffect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,11 @@ export function createEffect<Params, Done, Fail = Error>(
scope: {
handler:
instance.defaultConfig.handler ||
(() => assert(false, `no handler used in ${instance.getType()}`)),
(() =>
assert(
false,
`no handler used in ${instance.compositeName.fullName}`,
)),
},
node: [
calc(
Expand Down
5 changes: 4 additions & 1 deletion src/effector/createUnit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ export const initUnit = (kind: Kind, unit: any, rawConfig: any) => {
deprecate(false, 'thru', 'js pipe')
return fn(unit)
}
unit.getType = () => compositeName.fullName
unit.getType = () => {
deprecate(false, 'getType', 'compositeName.fullName')
return compositeName.fullName
}
if (!isDomain) {
unit.subscribe = (observer: Subscriber<any>) => {
assertObject(observer)
Expand Down