Code Monkey home page Code Monkey logo

Comments (16)

robisim74 avatar robisim74 commented on May 27, 2024 1

@FabienDehopre Thanks for reporting. I'll update you when I'll release the new version

from angular-l10n.

robisim74 avatar robisim74 commented on May 27, 2024 1

Tonight I'll release the new minor version. In a few days the new major version. Both will have this features.

from angular-l10n.

robisim74 avatar robisim74 commented on May 27, 2024

I don't know why you are using OnPush change detection strategy, but it's normal that the pure pipes don't work if you use it, because the input parameter (lang) is updated by an event when the http request is completed.

from angular-l10n.

FabienDehopre avatar FabienDehopre commented on May 27, 2024

It seems odd to me because I use other pure pipe in my components with OnPush change detection strategy and I don't have any issue.
In the first place, I use the OnPush change detection strategy for performance reason. I have long list of bound items.
Also, I use @ngrx/store for my state management.. so I might store the current language and locale in my store and subscribe to your observables/events to update the central application store. Or temporarily disable onpush on my components

from angular-l10n.

robisim74 avatar robisim74 commented on May 27, 2024

I may have found a solution: because the input parameter is updated by a subscription, I can add the calling to the markForCheck API in the Locale class in this way:

    constructor(public locale?: LocaleService, public localization?: LocalizationService, public changeDetectorRef?: ChangeDetectorRef) {

        if (this.localization != null) {

            this.lang = this.localization.languageCode;

            // When the language changes, subscribes to the event & updates lang property.
            this.localization.translationChanged.subscribe(

                // Generator or next.
                (language: string) => {
                    this.lang = language;
                    if (this.changeDetectorRef) { this.changeDetectorRef.markForCheck() }; // OnPush Change Detection strategy.
                }

            );

        }
...

But then you have to pass a new parameter to the Locale superclass when you use in the component changeDetection: ChangeDetectionStrategy.OnPush:

constructor(public locale: LocaleService, public localization: LocalizationService, public cd: ChangeDetectorRef) {
        super(locale, localization, cd);

What do you think?

from angular-l10n.

FabienDehopre avatar FabienDehopre commented on May 27, 2024

I think it's a good idea.
It's not a big deal to pass one more argument to the base class.
I already have base classes for my services with more than 3 arguments in the super constructor.

from angular-l10n.

robisim74 avatar robisim74 commented on May 27, 2024

I made the commit that adds support for OnPush Change Detection strategy.

You should remove the library from your npm modules, and follow the instructions in the README to build & install the library locally.

Please, try it in your app, and let me know if it works fine, so I'll include this support in the next release.

P.S. Just to explain: because the input parameter of the pure pipes changes when the http request is completed (ie after the event has been generated), markForCheck method generates an event that allows the OnPush strategy to update the value. More explanation here: https://blog.thoughtram.io/angular/2016/02/22/angular-2-change-detection-explained.html

from angular-l10n.

FabienDehopre avatar FabienDehopre commented on May 27, 2024

ok. I will test your change monday morning.
I'll keep you posted.

from angular-l10n.

skyfremen avatar skyfremen commented on May 27, 2024

Understand that pure pipes don't work, because the input parameter (lang) is updated by an event when the http request is completed.

How should I reflect the changes of the pure pipes using locale.setCurrentLocale();?
I am not using OnPush change detection strategy*

from angular-l10n.

FabienDehopre avatar FabienDehopre commented on May 27, 2024

@robisim74 Your change is working fine :-)
You can include this change in the next release.

from angular-l10n.

robisim74 avatar robisim74 commented on May 27, 2024

@skyfremen You have to extend the Locale superclass in your components: it provides the subscriptions to update the parameters. If you have problems, please open a new issue

from angular-l10n.

FabienDehopre avatar FabienDehopre commented on May 27, 2024

any idea when you will release this change ?

from angular-l10n.

robisim74 avatar robisim74 commented on May 27, 2024

New minor version is out.

from angular-l10n.

robisim74 avatar robisim74 commented on May 27, 2024

@FabienDehopre I'm closing this issue. If you need, open a new issue. Greetings

from angular-l10n.

macwier avatar macwier commented on May 27, 2024

@robisim74

Hi, just a question: Would it be possible to get the same behaviour by using both the @Language decorator and @input on the lang: string property?

from angular-l10n.

robisim74 avatar robisim74 commented on May 27, 2024

Hi @MaciejWierzchowski, did you try it?

from angular-l10n.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.