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

Solving circular import hack #444

Merged
merged 1 commit into from
Feb 3, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/nlp/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import ToText, { DateFormatter, GetText } from './totext'
import parseText from './parsetext'
import RRule from '../index'
import { Frequency } from '../types'
import ENGLISH, { Language } from './i18n'

/*!
Expand Down Expand Up @@ -108,12 +109,12 @@ const common = [
]

ToText.IMPLEMENTED = []
ToText.IMPLEMENTED[RRule.HOURLY] = common
ToText.IMPLEMENTED[RRule.MINUTELY] = common
ToText.IMPLEMENTED[RRule.DAILY] = ['byhour'].concat(common)
ToText.IMPLEMENTED[RRule.WEEKLY] = common
ToText.IMPLEMENTED[RRule.MONTHLY] = common
ToText.IMPLEMENTED[RRule.YEARLY] = ['byweekno', 'byyearday'].concat(common)
ToText.IMPLEMENTED[Frequency.HOURLY] = common
ToText.IMPLEMENTED[Frequency.MINUTELY] = common
ToText.IMPLEMENTED[Frequency.DAILY] = ['byhour'].concat(common)
ToText.IMPLEMENTED[Frequency.WEEKLY] = common
ToText.IMPLEMENTED[Frequency.MONTHLY] = common
ToText.IMPLEMENTED[Frequency.YEARLY] = ['byweekno', 'byyearday'].concat(common)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


// =============================================================================
// Export
Expand Down
23 changes: 5 additions & 18 deletions src/rrule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import dateutil from './dateutil'
import IterResult, { IterArgs } from './iterresult'
import CallbackIterResult from './callbackiterresult'
import { Language } from './nlp/i18n'
import { Nlp } from './nlp/index'
import { fromText, parseText, toText, isFullyConvertible } from './nlp/index'
import { DateFormatter, GetText } from './nlp/totext'
import { ParsedOptions, Options, Frequency, QueryMethods, QueryMethodTypes, IterResultType } from './types'
import { parseOptions, initializeOptions } from './parseoptions'
Expand All @@ -13,19 +13,6 @@ import { Cache, CacheKeys } from './cache'
import { Weekday } from './weekday'
import { iter } from './iter/index'

interface GetNlp {
_nlp: Nlp
(): Nlp
}

const getnlp: GetNlp = function () {
// Lazy, runtime import to avoid circular refs.
if (!getnlp._nlp) {
getnlp._nlp = require('./nlp')
}
return getnlp._nlp
} as GetNlp
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rationale for this IIRC was to make nlp an optional dependency - I had in mind to eventually split it out into its own package. But this simplifies things for now, so we should merge it.


// =============================================================================
// RRule
// =============================================================================
Expand Down Expand Up @@ -114,11 +101,11 @@ export default class RRule implements QueryMethods {
}

static parseText (text: string, language?: Language) {
return getnlp().parseText(text, language)
return parseText(text, language)
}

static fromText (text: string, language?: Language) {
return getnlp().fromText(text, language)
return fromText(text, language)
}

static parseString = parseString
Expand Down Expand Up @@ -256,11 +243,11 @@ export default class RRule implements QueryMethods {
* to text.
*/
toText (gettext?: GetText, language?: Language, dateFormatter?: DateFormatter) {
return getnlp().toText(this, gettext, language, dateFormatter)
return toText(this, gettext, language, dateFormatter)
}

isFullyConvertibleToText () {
return getnlp().isFullyConvertible(this)
return isFullyConvertible(this)
}

/**
Expand Down