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

Refactor our context providers to the new context API #1946

Closed
borisyankov opened this issue Feb 19, 2018 · 6 comments · Fixed by #4199
Closed

Refactor our context providers to the new context API #1946

borisyankov opened this issue Feb 19, 2018 · 6 comments · Fixed by #4199

Comments

@borisyankov
Copy link
Contributor

React 16.3 will introduce a new official API for working with context.
When React Native migrates to this React version (likely in the next version 0.54) we can rework our contexts to use this new API.

@divyabaid16
Copy link

I would like to work on this issue. Can you plz guide me ?

@borisyankov
Copy link
Contributor Author

I am not yet familiar enough with the new context API :)
It is not urgent enough, so I am focusing my efforts on other areas of the app.

This issue would be interesting and appropriate for a student that wants to learn this on his own.

@robgev
Copy link
Collaborator

robgev commented Mar 23, 2018

@zulipbot claim

@zulipbot
Copy link
Member

Welcome to Zulip, @robgev! We just sent you an invite to collaborate on this repository at https://github.com/zulip/zulip-mobile/invitations. Please accept this invite in order to claim this issue and begin a fun, rewarding experience contributing to Zulip!

Here's some tips to get you off to a good start:

As you work on this issue, you'll also want to refer to the Zulip code contribution guide, as well as the rest of the developer documentation on that site.

See you on the other side (that is, the pull request side)!

@parshva-b
Copy link

Hey, I am Parshva Barbhaya, new to opensource and this community and want to participate in GSoC under this organization. I would like to work on this issue, but do need some guidance.

chrisbobbe pushed a commit to chrisbobbe/zulip-mobile that referenced this issue Jan 29, 2020
Per zulip#1946, we're moving to the new React Context API
(https://reactjs.org/docs/context.html).

We’re also isolating the theme colors in its own context type. So,
components that consume the theme colors can and should use `static
contextType = ThemeContext;` and, e.g.,
this.context.backgroundColor, instead of
this.context.styles.backgroundColor, as was done before.

This change also eliminates the need for miscStyles.webview, which
was included in this.context.styles that MessageList was using, so,
remove that.
@gnprice
Copy link
Member

gnprice commented Jan 29, 2020

Some quick notes on what this means, partly to refresh myself:

  • The only thing we use the old context API for is for a styles object. You can find uses with git grep contextTypes.
    • There's one exception: TranslationProvider uses the old API. A block comment there explains why that one is OK.
    • There are 14 of these left.
  • See commit 51dd1b3, specifically its changes to LineSeparator.js and miscStyles.js, for an example of converting from the old to the new API. (Ignore the other files that commit touches; those were one-time changes to make such conversions possible. In retrospect I'd have done better to split it into two commits.)

chrisbobbe pushed a commit to chrisbobbe/zulip-mobile that referenced this issue Jan 29, 2020
Per zulip#1946, we're moving to the new React Context API
(https://reactjs.org/docs/context.html).

We’re also isolating the theme colors in their own context type, to
be accessed from there instead of the previously used
`context.styles` object. So, components that consume the theme
colors can and should use `static contextType = ThemeContext;` and,
e.g., this.context.backgroundColor, instead of
this.context.styles.backgroundColor, as was done before.

This change also eliminates the need for miscStyles.webview, which
was included in this.context.styles that MessageList was using, so,
remove that.
gnprice pushed a commit to chrisbobbe/zulip-mobile that referenced this issue Feb 1, 2020
Per zulip#1946, we're moving to the new React Context API
(https://reactjs.org/docs/context.html).

We’re also isolating the theme colors in their own context type, to
be accessed from there instead of the previously used
`context.styles` object. So, components that consume the theme
colors can and should use `static contextType = ThemeContext;` and,
e.g., this.context.backgroundColor, instead of
this.context.styles.backgroundColor, as was done before.

This change also eliminates the need for miscStyles.webview, which
was included in this.context.styles that MessageList was using, so,
remove that.
@chrisbobbe chrisbobbe self-assigned this Apr 14, 2020
chrisbobbe pushed a commit to chrisbobbe/zulip-mobile that referenced this issue Apr 16, 2020
(Commit message largely copied from that of a606bf3.)

Per zulip#1946, we're moving to the new React Context API
(https://reactjs.org/docs/context.html).

We’re also isolating the theme colors in their own context type, to
be accessed from there instead of the previously used
`context.styles` object. So, components that consume the theme
colors can and should use `static contextType = ThemeContext;` and,
e.g., this.context.backgroundColor, instead of
this.context.styles.backgroundColor, as was done before.
chrisbobbe pushed a commit to chrisbobbe/zulip-mobile that referenced this issue Apr 16, 2020
Per zulip#1946, we're moving to the new React Context API
(https://reactjs.org/docs/context.html).

Use the same strategy as in the parent, for SmartUrlInput.

Also, replace what looks like an ill-considered use of
StyleSheet.flatten, which takes an array of objects:

> Flattens an array of style objects, into one aggregated style
> object. Alternatively, this method can be used to lookup IDs,
> returned by StyleSheet.register.

(https://reactnative.dev/docs/stylesheet#flatten)
chrisbobbe pushed a commit to chrisbobbe/zulip-mobile that referenced this issue Apr 16, 2020
Per zulip#1946, we're moving to the new React Context API
(https://reactjs.org/docs/context.html).

For details like height, margin, flex that are about the component
and not the theme, put these in the existing `componentStyles`
object. Taking advantage of this pre-existing object means differing
from the pattern introduced in a2bfcb4, and recommended there and
in 51dd1b3, of using an instance field. I'd be happy to move all
of `componentStyles` to an instance field; I just think it's most
natural for the non-theme-dependent styles to live together.

An additional, more meaningful departure from a2bfcb4 and
51dd1b3 is to put the theme-dependent styles (the colors) in the
render method, so that a persistently mounted component is
live-updated upon changing the theme.

In practice, the lack of live-updating has probably never been
observed, as a side-effect of the `key={theme}` hack in
src/boot/StylesProvider.js, which causes most of the entire tree to
be remounted (not rerendered, remounted) when the theme changes.
This hack is explained in docs/architecture/react.md#context, and it
will be removed at the end of this series of commits, since the new
Context API makes it unnecessary.

Also, I don't think this component is even visible when the user
goes into their settings to change the theme. Even so, I think this
is the correct way to handle a value that, in theory, could change
at any time.
chrisbobbe pushed a commit to chrisbobbe/zulip-mobile that referenced this issue Apr 16, 2020
Per zulip#1946, we're moving to the new React Context API
(https://reactjs.org/docs/context.html).

Use exactly the same strategy as we did for Screen, in the parent.
chrisbobbe pushed a commit to chrisbobbe/zulip-mobile that referenced this issue Apr 16, 2020
Per zulip#1946, we're moving to the new React Context API
(https://reactjs.org/docs/context.html).

As in the last few commits, put the theme-dependent values in the
render method for live-updating when the theme changes. For details
like height, margin, flex that are about the component and not the
theme, put these in a `styles` object.

This time, I made a `styles` object, with StyleSheet.create, where
none existed before. (Following 373fed8, I named it just `styles`
instead of `componentStyles`.) As earlier, I'd be happy to put these
in an instance field if preferred.
chrisbobbe pushed a commit to chrisbobbe/zulip-mobile that referenced this issue Apr 16, 2020
Per zulip#1946, we're moving to the new React Context API
(https://reactjs.org/docs/context.html).

Use exactly the same strategy as we did for Input, in a recent
commit.
chrisbobbe pushed a commit to chrisbobbe/zulip-mobile that referenced this issue Apr 16, 2020
Per zulip#1946, we're moving to the new React Context API
(https://reactjs.org/docs/context.html).

Use exactly the same strategy as we did for Label, in the parent.
chrisbobbe pushed a commit to chrisbobbe/zulip-mobile that referenced this issue Apr 16, 2020
chrisbobbe pushed a commit to chrisbobbe/zulip-mobile that referenced this issue Apr 25, 2020
(Commit message largely copied from that of a606bf3.)

Per zulip#1946, we're moving to the new React Context API
(https://reactjs.org/docs/context.html).

We’re also isolating the theme colors in their own context type, to
be accessed from there instead of the previously used
`context.styles` object. So, components that consume the theme
colors can and should use `static contextType = ThemeContext;` and,
e.g., this.context.backgroundColor, instead of
this.context.styles.backgroundColor, as was done before.
chrisbobbe pushed a commit to chrisbobbe/zulip-mobile that referenced this issue Apr 25, 2020
Per zulip#1946, we're moving to the new React Context API
(https://reactjs.org/docs/context.html).

Use the same strategy as in the parent commit, for SmartUrlInput.

Also, remove what looks like an ill-considered use of
StyleSheet.flatten, which takes an array of objects:

> Flattens an array of style objects, into one aggregated style
> object. Alternatively, this method can be used to lookup IDs,
> returned by StyleSheet.register.

(https://reactnative.dev/docs/stylesheet#flatten)
chrisbobbe pushed a commit to chrisbobbe/zulip-mobile that referenced this issue Apr 25, 2020
Per zulip#1946, we're moving to the new React Context API
(https://reactjs.org/docs/context.html).

For details like height, margin, and flex that are about the
component and not the theme, put these in the existing
`componentStyles` object.

A functional difference between this pattern and the one in, e.g.,
a2bfcb4 and 51dd1b3, is that, here, we don't group the
theme-dependent styles together with the constant ones. If we don't
compute the theme-dependent styles in the `render` method, then the
component's appearance won't live-update when the theme is changed.

A universal choice between the non-functional difference between
using an instance field and an outer-level `const` declaration
hasn't been made, but there's been some fruitful discussion [1],
quoted in the next commit. Here, we just go with the existing
`const` declaration.

In practice, the lack of live-updating has probably never been
observed, as a side-effect of the `key={theme}` hack in
src/boot/StylesProvider.js, which causes most of the entire tree to
be remounted (not rerendered, remounted) when the theme changes.
This hack is explained in docs/architecture/react.md#context, and it
will be removed at the end of this series of commits, since the new
Context API makes it unnecessary. Before that happens, the latent
bugs in a2bfcb4 and 51dd1b3 (mentioned above), and elsewhere,
will be fixed.

[1]: https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/Styles.20in.20component.20files/near/860528
gnprice pushed a commit to chrisbobbe/zulip-mobile that referenced this issue May 1, 2020
As foreshadowed in this series, we get to remove the `key={theme}`
hack (along with some boilerplate to get things all working with the
old Context API).

So, also, remove a bit of documentation that explained the hack. The
section was necessary, previously, but it hindered an easy
understanding of the "Pure Component Principle" and our use of it,
which is a main idea of that doc.

Fixes: zulip#1946
chrisbobbe pushed a commit to chrisbobbe/zulip-mobile that referenced this issue Jul 20, 2020
Per zulip#1946, we're moving to the new React Context API
(https://reactjs.org/docs/context.html).

For details like height, margin, and flex that are about the
component and not the theme, put these in the existing
`componentStyles` object.

A functional difference between this pattern and the one in, e.g.,
a2bfcb4 and 51dd1b3, is that, here, we don't group the
theme-dependent styles together with the constant ones. If we don't
compute the theme-dependent styles in the `render` method, then the
component's appearance won't live-update when the theme is changed.

A universal choice between the non-functional difference between
using an instance field and an outer-level `const` declaration
hasn't been made, but there's been some fruitful discussion [1],
quoted in the next commit. Here, we just go with the existing
`const` declaration.

In practice, the lack of live-updating has probably never been
observed, as a side-effect of the `key={theme}` hack in
src/boot/StylesProvider.js, which causes most of the entire tree to
be remounted (not rerendered, remounted) when the theme changes.
This hack is explained in docs/architecture/react.md#context, and it
will be removed at the end of this series of commits, since the new
Context API makes it unnecessary. Before that happens, the latent
bugs in a2bfcb4 and 51dd1b3 (mentioned above), and elsewhere,
will be fixed.

[1]: https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/Styles.20in.20component.20files/near/860528
chrisbobbe pushed a commit to chrisbobbe/zulip-mobile that referenced this issue Jul 20, 2020
Per zulip#1946, we're moving to the new React Context API
(https://reactjs.org/docs/context.html).

As in the parent commit, for Screen, separate the constant parts of
the style from those that change with the theme; the latter get
computed in the render method.

Differing from the parent commit, put the constant parts of the
style in an instance field, rather than an outer-level `const`
declaration. We haven't settled the question universally; in
discussion [1], Greg points out,

"""
There's a tension between two things that are good to have:

* The render method, particularly the blob of JSX that's typically
found all at the end, is where we describe the visual look of the
component. It'd be good for the description of its visual look to be
all in one place, or at least reasonably close together, and the
styles are part of that.

* The styles are often kind of long with a lot of fairly boring
stuff, and it's good to be able to see all the other stuff going on
in `render` -- often including logic about what to show at all, or
what data to use -- without the more boring of the styles details
pushing it off the screen.
"""

Putting it an instance property means it's closer at hand than at a
`const` above the class definition, so, slightly favor that pattern
by using it in this file, where there's no precedent (or there was a
precedent, and it was recently removed in 8621b61, before this
series of commits).

[1]: https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/Styles.20in.20component.20files/near/860528
chrisbobbe pushed a commit to chrisbobbe/zulip-mobile that referenced this issue Jul 20, 2020
Per zulip#1946, we're moving to the new React Context API
(https://reactjs.org/docs/context.html).

Use the same strategy as in a recent commit, for ChatScreen: put the
constant parts of the style in an instance field, and compute the
theme-dependent parts in the `render` method.
chrisbobbe pushed a commit to chrisbobbe/zulip-mobile that referenced this issue Jul 20, 2020
Per zulip#1946, we're moving to the new React Context API
(https://reactjs.org/docs/context.html).

Use the same strategy as in recent commits, for Input and
ChatScreen: put the constant parts of the style in an instance
field, and compute the theme-dependent parts in the `render` method.
chrisbobbe pushed a commit to chrisbobbe/zulip-mobile that referenced this issue Jul 20, 2020
Per zulip#1946, we're moving to the new React Context API
(https://reactjs.org/docs/context.html).

Use the same strategy as in recent commits, for Label, Input, and
ChatScreen: put the constant parts of the style in an instance
field, and compute the theme-dependent parts in the `render` method.
chrisbobbe pushed a commit to chrisbobbe/zulip-mobile that referenced this issue Jul 20, 2020
Continuing the work of recent commits toward zulip#1946.

These last few consumers are simply using `background` or
`backgroundColor` from the old style context, and no
theme-independent styles, so, fix them together in one commit.

Then, to help verify that all consumers are removed:

Atomically, in this commit, remove the default-exported function of
`miscStyles`, and its only call site, at `stylesFromTheme`.
`stylesFromTheme` is the single point where all the data is
collected and distributed as `styles` via the legacy Context API. (A
similar removal, for `navStyles`, is bfdde6f.)
chrisbobbe pushed a commit to chrisbobbe/zulip-mobile that referenced this issue Jul 20, 2020
As foreshadowed in this series, we get to remove the `key={theme}`
hack (along with some boilerplate to get things all working with the
old Context API).

So, also, remove a bit of documentation that explained the hack. The
section was necessary, previously, but it hindered an easy
understanding of the "Pure Component Principle" and our use of it,
which is a main idea of that doc.

Fixes: zulip#1946
chrisbobbe pushed a commit to chrisbobbe/zulip-mobile that referenced this issue Jul 20, 2020
Per zulip#1946, we're moving to the new React Context API
(https://reactjs.org/docs/context.html).

For details like height, margin, and flex that are about the
component and not the theme, put these in the existing
`componentStyles` object.

A functional difference between this pattern and the one in, e.g.,
a2bfcb4 and 51dd1b3, is that, here, we don't group the
theme-dependent styles together with the constant ones. If we don't
compute the theme-dependent styles in the `render` method, then the
component's appearance won't live-update when the theme is changed.

A universal choice between the non-functional difference between
using an instance field and an outer-level `const` declaration
hasn't been made, but there's been some fruitful discussion [1],
quoted in the next commit. Here, we just go with the existing
`const` declaration.

In practice, the lack of live-updating has probably never been
observed, as a side-effect of the `key={theme}` hack in
src/boot/StylesProvider.js, which causes most of the entire tree to
be remounted (not rerendered, remounted) when the theme changes.
This hack is explained in docs/architecture/react.md#context, and it
will be removed at the end of this series of commits, since the new
Context API makes it unnecessary. Before that happens, the latent
bugs in a2bfcb4 and 51dd1b3 (mentioned above), and elsewhere,
will be fixed.

[1]: https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/Styles.20in.20component.20files/near/860528
chrisbobbe pushed a commit to chrisbobbe/zulip-mobile that referenced this issue Jul 20, 2020
Per zulip#1946, we're moving to the new React Context API
(https://reactjs.org/docs/context.html).

As in the parent commit, for Screen, separate the constant parts of
the style from those that change with the theme; the latter get
computed in the render method.

Differing from the parent commit, put the constant parts of the
style in an instance field, rather than an outer-level `const`
declaration. We haven't settled the question universally; in
discussion [1], Greg points out,

"""
There's a tension between two things that are good to have:

* The render method, particularly the blob of JSX that's typically
found all at the end, is where we describe the visual look of the
component. It'd be good for the description of its visual look to be
all in one place, or at least reasonably close together, and the
styles are part of that.

* The styles are often kind of long with a lot of fairly boring
stuff, and it's good to be able to see all the other stuff going on
in `render` -- often including logic about what to show at all, or
what data to use -- without the more boring of the styles details
pushing it off the screen.
"""

Putting it an instance property means it's closer at hand than at a
`const` above the class definition, so, slightly favor that pattern
by using it in this file, where there's no precedent (or there was a
precedent, and it was recently removed in 8621b61, before this
series of commits).

[1]: https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/Styles.20in.20component.20files/near/860528
chrisbobbe pushed a commit to chrisbobbe/zulip-mobile that referenced this issue Jul 20, 2020
Per zulip#1946, we're moving to the new React Context API
(https://reactjs.org/docs/context.html).

Use the same strategy as in a recent commit, for ChatScreen: put the
constant parts of the style in an instance field, and compute the
theme-dependent parts in the `render` method.
chrisbobbe pushed a commit to chrisbobbe/zulip-mobile that referenced this issue Jul 20, 2020
Per zulip#1946, we're moving to the new React Context API
(https://reactjs.org/docs/context.html).

Use the same strategy as in recent commits, for Input and
ChatScreen: put the constant parts of the style in an instance
field, and compute the theme-dependent parts in the `render` method.
chrisbobbe pushed a commit to chrisbobbe/zulip-mobile that referenced this issue Jul 20, 2020
Per zulip#1946, we're moving to the new React Context API
(https://reactjs.org/docs/context.html).

Use the same strategy as in recent commits, for Label, Input, and
ChatScreen: put the constant parts of the style in an instance
field, and compute the theme-dependent parts in the `render` method.
chrisbobbe pushed a commit to chrisbobbe/zulip-mobile that referenced this issue Jul 20, 2020
Continuing the work of recent commits toward zulip#1946.

These last few consumers are simply using `background` or
`backgroundColor` from the old style context, and no
theme-independent styles, so, fix them together in one commit.

Then, to help verify that all consumers are removed:

Atomically, in this commit, remove the default-exported function of
`miscStyles`, and its only call site, at `stylesFromTheme`.
`stylesFromTheme` is the single point where all the data is
collected and distributed as `styles` via the legacy Context API. (A
similar removal, for `navStyles`, is bfdde6f.)
chrisbobbe pushed a commit to chrisbobbe/zulip-mobile that referenced this issue Jul 20, 2020
As foreshadowed in this series, we get to remove the `key={theme}`
hack (along with some boilerplate to get things all working with the
old Context API).

So, also, remove a bit of documentation that explained the hack. The
section was necessary, previously, but it hindered an easy
understanding of the "Pure Component Principle" and our use of it,
which is a main idea of that doc.

Fixes: zulip#1946
gnprice pushed a commit that referenced this issue Jul 22, 2020
Per #1946, we're moving to the new React Context API
(https://reactjs.org/docs/context.html).

For details like height, margin, and flex that are about the
component and not the theme, put these in the existing
`componentStyles` object.

A functional difference between this pattern and the one in, e.g.,
a2bfcb4 and 51dd1b3, is that, here, we don't group the
theme-dependent styles together with the constant ones. If we don't
compute the theme-dependent styles in the `render` method, then the
component's appearance won't live-update when the theme is changed.

A universal choice between the non-functional difference between
using an instance field and an outer-level `const` declaration
hasn't been made, but there's been some fruitful discussion [1],
quoted in the next commit. Here, we just go with the existing
`const` declaration.

In practice, the lack of live-updating has probably never been
observed, as a side-effect of the `key={theme}` hack in
src/boot/StylesProvider.js, which causes most of the entire tree to
be remounted (not rerendered, remounted) when the theme changes.
This hack is explained in docs/architecture/react.md#context, and it
will be removed at the end of this series of commits, since the new
Context API makes it unnecessary. Before that happens, the latent
bugs in a2bfcb4 and 51dd1b3 (mentioned above), and elsewhere,
will be fixed.

[1]: https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/Styles.20in.20component.20files/near/860528
gnprice pushed a commit that referenced this issue Jul 22, 2020
Per #1946, we're moving to the new React Context API
(https://reactjs.org/docs/context.html).

As in the parent commit, for Screen, separate the constant parts of
the style from those that change with the theme; the latter get
computed in the render method.

Differing from the parent commit, put the constant parts of the
style in an instance field, rather than an outer-level `const`
declaration. We haven't settled the question universally; in
discussion [1], Greg points out,

"""
There's a tension between two things that are good to have:

* The render method, particularly the blob of JSX that's typically
found all at the end, is where we describe the visual look of the
component. It'd be good for the description of its visual look to be
all in one place, or at least reasonably close together, and the
styles are part of that.

* The styles are often kind of long with a lot of fairly boring
stuff, and it's good to be able to see all the other stuff going on
in `render` -- often including logic about what to show at all, or
what data to use -- without the more boring of the styles details
pushing it off the screen.
"""

Putting it an instance property means it's closer at hand than at a
`const` above the class definition, so, slightly favor that pattern
by using it in this file, where there's no precedent (or there was a
precedent, and it was recently removed in 8621b61, before this
series of commits).

[1]: https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/Styles.20in.20component.20files/near/860528
gnprice pushed a commit that referenced this issue Jul 22, 2020
Per #1946, we're moving to the new React Context API
(https://reactjs.org/docs/context.html).

Use the same strategy as in a recent commit, for ChatScreen: put the
constant parts of the style in an instance field, and compute the
theme-dependent parts in the `render` method.
gnprice pushed a commit that referenced this issue Jul 22, 2020
Per #1946, we're moving to the new React Context API
(https://reactjs.org/docs/context.html).

Use the same strategy as in recent commits, for Input and
ChatScreen: put the constant parts of the style in an instance
field, and compute the theme-dependent parts in the `render` method.
gnprice pushed a commit that referenced this issue Jul 22, 2020
Per #1946, we're moving to the new React Context API
(https://reactjs.org/docs/context.html).

Use the same strategy as in recent commits, for Label, Input, and
ChatScreen: put the constant parts of the style in an instance
field, and compute the theme-dependent parts in the `render` method.
gnprice pushed a commit that referenced this issue Jul 22, 2020
Continuing the work of recent commits toward #1946.

These last few consumers are simply using `background` or
`backgroundColor` from the old style context, and no
theme-independent styles, so, fix them together in one commit.

Then, to help verify that all consumers are removed:

Atomically, in this commit, remove the default-exported function of
`miscStyles`, and its only call site, at `stylesFromTheme`.
`stylesFromTheme` is the single point where all the data is
collected and distributed as `styles` via the legacy Context API. (A
similar removal, for `navStyles`, is bfdde6f.)
chrisbobbe pushed a commit to chrisbobbe/zulip-mobile that referenced this issue Jul 24, 2020
As foreshadowed in this series, we get to remove the `key={theme}`
hack (along with some boilerplate to get things all working with the
old Context API).

So, also, remove a bit of documentation that explained the hack. The
section was necessary, previously, but it hindered an easy
understanding of the "Pure Component Principle" and our use of it,
which is a main idea of that doc.

Fixes: zulip#1946
chrisbobbe pushed a commit to chrisbobbe/zulip-mobile that referenced this issue Jul 24, 2020
As foreshadowed in this series, we get to remove the `key={theme}`
hack (along with some boilerplate to get things all working with the
old Context API).

So, also, remove a bit of documentation that explained the hack. The
section was necessary, previously, but it hindered an easy
understanding of the "Pure Component Principle" and our use of it,
which is a main idea of that doc.

Fixes: zulip#1946
chrisbobbe added a commit to chrisbobbe/zulip-mobile that referenced this issue Jul 24, 2020
In putting together a recent commit, I realized that this would be
possible if our `TranslationContextTranslator` more carefully spoke
the language of the old Context API. By making it a `Component`
instead of a `PureComponent`, and making sure there aren't any
disruptive ancestors between it and IntlProvider (in particular,
there are *no* ancestors at all) it'll be updated when `intl`
changes.

It already speaks the new Context API as well as it needs to (i.e.,
nothing special has to happen to get its consumers to update), and
we don't have any consumers that directly consume the old one
straight from `react-intl`.

One necessary tweak was to stop using `this._`, which is only set in
the constructor. (Reminiscent of b530f6c, when we were removing
the `key` hack for styles.)

Fixes: zulip#1946
chrisbobbe added a commit to chrisbobbe/zulip-mobile that referenced this issue Jul 28, 2020
In putting together a recent commit, I realized that this would be
possible if our `TranslationContextTranslator` more carefully spoke
the language of the old Context API. By making it a `Component`
instead of a `PureComponent`, and making sure there aren't any
disruptive ancestors between it and IntlProvider (in particular,
there are *no* ancestors at all) it'll be updated when `intl`
changes.

It already speaks the new Context API as well as it needs to (i.e.,
nothing special has to happen to get its consumers to update), and
we don't have any consumers that directly consume the old one
straight from `react-intl`.

One necessary tweak was to stop using `this._`, which is only set in
the constructor. (Reminiscent of b530f6c, when we were removing
the `key` hack for styles.)

Fixes: zulip#1946
chrisbobbe added a commit to chrisbobbe/zulip-mobile that referenced this issue Jul 28, 2020
In putting together a recent commit, I realized that this would be
possible if our `TranslationContextTranslator` more carefully spoke
the language of the old Context API. By making it a `Component`
instead of a `PureComponent`, and making sure there aren't any
disruptive ancestors between it and IntlProvider (in particular,
there are *no* ancestors at all) it'll be updated when `intl`
changes.

It already speaks the new Context API as well as it needs to (i.e.,
nothing special has to happen to get its consumers to update), and
we don't have any consumers that directly consume the old one
straight from `react-intl`.

One necessary tweak was to stop using `this._`, which is only set in
the constructor. (Reminiscent of b530f6c, when we were removing
the `key` hack for styles.)

Fixes: zulip#1946
chrisbobbe added a commit to chrisbobbe/zulip-mobile that referenced this issue Jul 28, 2020
In putting together a recent commit, I realized that this would be
possible if our `TranslationContextTranslator` more carefully spoke
the language of the old Context API. By making it a `Component`
instead of a `PureComponent`, and making sure there aren't any
disruptive ancestors between it and IntlProvider (in particular,
there are *no* ancestors at all) it'll be updated when `intl`
changes.

It already speaks the new Context API as well as it needs to (i.e.,
nothing special has to happen to get its consumers to update), and
we don't have any consumers that directly consume the old one
straight from `react-intl`.

One necessary tweak was to stop using `this._`, which is only set in
the constructor. (Reminiscent of b530f6c, when we were removing
the `key` hack for styles.)

Fixes: zulip#1946
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment