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

Theme Middleware #392

Merged
merged 4 commits into from
Jun 13, 2019
Merged

Theme Middleware #392

merged 4 commits into from
Jun 13, 2019

Conversation

agubler
Copy link
Member

@agubler agubler commented Jun 7, 2019

Type: feature

The following has been addressed in the PR:

Description:

Theme middleware to work to determine the correct classes based on the current theme & set themes.

Resolves #371

import { SupportedClassName } from '../interfaces';
import Injector from '../Injector';

export interface ClassNames {
Copy link
Member Author

Choose a reason for hiding this comment

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

These interfaces should be reused from the existing Themed class

cache.set(css, theme);
return theme;
},
set(css?: Theme) {
Copy link
Member Author

Choose a reason for hiding this comment

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

This API is confusing as it's not the opposite of get, it actually sets the current theme - also need an API to register a theme, registering a theme would make it available and only set it if no theme is currently set.

@@ -34,6 +34,10 @@ export class RegistryHandler extends Evented<RegistryHandlerEventMap> {
this.baseRegistry = baseRegistry;
}

public get base(): Registry {
Copy link
Member Author

Choose a reason for hiding this comment

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

Exposes the base registry - this is the app level repository.

@@ -813,7 +813,7 @@ export function renderer(renderer: () => RenderResult): Renderer {
merge: true,
transition: transitionStrategy,
domNode: global.document.body,
registry: null
registry: new Registry()
Copy link
Member Author

Choose a reason for hiding this comment

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

Add a Registry by default to the application if one is not passed by the user - this means things like the theme middleware will work without passing a registry to the mount

@agubler agubler changed the title [WIP] Theme Middleware Theme Middleware Jun 13, 2019
@@ -26,7 +26,7 @@ export function reference(previousProperty: any, newProperty: any): PropertyChan
};
}

export function shallow(previousProperty: any, newProperty: any): PropertyChangeRecord {
export function shallow(previousProperty: any, newProperty: any, depth = 0): PropertyChangeRecord {
Copy link
Member Author

Choose a reason for hiding this comment

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

Adds support to choose the depth of the diff... defaults to 0 which is the equivalent of the current behaviour

const keys = [...themeKeys.values()];
for (let i = 0; i < keys.length; i++) {
let key = keys[i];
result = shallow(current.classes[key], next.classes[key], 1).changed;
Copy link
Member Author

Choose a reason for hiding this comment

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

Diffs the classes for every key that has been registered by the widget, the classes object is nested three levels so requires a slightly deeper diff than the standard shallow diff. To support this shallow accepts a depth param to control the level of the diff.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Theme Middleware
2 participants