-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fb4e95e
commit 4f274ad
Showing
27 changed files
with
284 additions
and
84 deletions.
There are no files selected for viewing
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { decoratorWithParams } from '@ember-decorators/utils/decorator'; | ||
import { computedDecorator } from '@ember-decorators/utils/computed'; | ||
import { assert } from '@ember/debug'; | ||
import extractValue from './utils/extract-value'; | ||
import { IntlComputedProperty } from 'ember-intl'; | ||
import IntlService from 'ember-intl/services/intl'; | ||
import { Descriptor } from '@ember-decorators/utils/decorator'; | ||
|
||
export default decoratorWithParams( | ||
(desc: Descriptor, dependentKeys: string[] = []) => { | ||
const { initializer } = desc; | ||
delete desc.initializer; | ||
|
||
return computedDecorator( | ||
desc => | ||
new IntlComputedProperty<object>(...dependentKeys, function( | ||
intl: IntlService, | ||
propertyKey: string | ||
) { | ||
const fn = extractValue({ ...desc, initializer }, this); | ||
assert( | ||
`@intl: You need to decorate a function, but you decorated '${fn}'.`, | ||
typeof fn === 'function' | ||
); | ||
|
||
return fn.call(this, intl, propertyKey); | ||
}) | ||
)(desc); | ||
} | ||
); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { macro } from '@ember-decorators/object/computed'; | ||
import { translationMacro } from 'ember-intl'; | ||
|
||
const t: (key: string, options?: object) => PropertyDecorator = macro( | ||
translationMacro | ||
); | ||
|
||
export default t; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import EmberObject from '@ember/object'; | ||
import { setOwner } from '@ember/application'; | ||
import TestContext from '../test-context'; | ||
|
||
export default function setupContainerObject(hooks: NestedHooks) { | ||
// @TODO: re-enable once TypeScript parser works properly | ||
// eslint-disable-next-line no-unused-vars | ||
hooks.beforeEach(function(this: TestContext) { | ||
const { owner } = this; | ||
|
||
class ContainerObject extends EmberObject { | ||
constructor() { | ||
super(); | ||
setOwner(this, owner); | ||
} | ||
} | ||
|
||
this.ContainerObject = ContainerObject; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import EmberObject from '@ember/object'; | ||
import { TestContext as BaseTextContext } from 'ember-intl/test-support'; | ||
|
||
export default interface TestContext extends BaseTextContext { | ||
ContainerObject: { new (): EmberObject }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// @TODO: re-enable once TypeScript parser works properly | ||
// eslint-disable-next-line no-unused-vars | ||
import ComputedProperty from '@ember/object/computed'; | ||
import { Descriptor } from './decorator'; | ||
|
||
export function computedDecorator( | ||
fn: (desc: Descriptor, params?: any[]) => ComputedProperty<any> | ||
): PropertyDecorator & ((desc: Descriptor) => Descriptor); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
interface Descriptor { | ||
initializer?: () => any; | ||
} | ||
|
||
export function decoratorWithParams<Params extends any[]>( | ||
fn: (desc: Descriptor, params?: Params) => Descriptor | ||
): ((...params: Params) => PropertyDecorator) & PropertyDecorator; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export { default as Service } from './services/intl'; | ||
export { default as translationMacro, raw } from './macro'; | ||
export { default as IntlComputedProperty } from './intl-computed-property'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import ComputedProperty from '@ember/object/computed'; | ||
import IntlService from './services/intl'; | ||
|
||
type GetterFn<Ctx> = ( | ||
this: Ctx, | ||
intl: IntlService, | ||
propertyKey: string, | ||
ctx: Ctx | ||
) => string; | ||
|
||
export default class IntlComputedProperty< | ||
Ctx extends object, | ||
Fn extends GetterFn<Ctx> = GetterFn<Ctx> | ||
> extends ComputedProperty<Fn> { | ||
constructor(...dependentKeysAndGetterFn: (string | Fn)[]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import IntlComputedProperty from './intl-computed-property'; | ||
|
||
/** | ||
* This class is used to box primitive types and mark them as raw literals that | ||
* should be used as is by the translation macro. | ||
* | ||
* This class is internal. Instead of using this class directly, use the `raw` | ||
* utility function, that creates an instance of this class. | ||
*/ | ||
declare class Raw<Value> { | ||
constructor(value: Value); | ||
valueOf(): Value; | ||
toString(): string; | ||
} | ||
|
||
/** | ||
* Use this utility function to mark a value as a raw literal. | ||
* | ||
* @param {*} value The value to mark as a raw literal. | ||
* @return The same value, but boxed in the `Raw` class so that the consuming | ||
* macro understands that this value should be used as is. | ||
*/ | ||
export function raw<Value>(value: Value): Raw<Value>; | ||
|
||
type OptionsFor<Ctx extends object> = { [key: string]: Raw<any> | keyof Ctx }; | ||
|
||
declare class TranslationMacro<Ctx extends object> extends IntlComputedProperty< | ||
Ctx | ||
> { | ||
constructor(translationKey: string, options?: OptionsFor<Ctx>); | ||
} | ||
|
||
export default function createTranslatedComputedProperty<Ctx extends object>( | ||
key: string, | ||
options?: OptionsFor<Ctx> | ||
): TranslationMacro<Ctx>; |
Oops, something went wrong.