Skip to content

Commit

Permalink
feat(): expose createStyle to create styles from a key
Browse files Browse the repository at this point in the history
  • Loading branch information
Enlcxx committed Jul 28, 2020
1 parent c1d09b5 commit c492df1
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions src/lib/src/minimal/renderer-style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,16 +290,14 @@ export function Style<INPUT = any, C = any>(
) {

return function(target: WithStyles, propertyKey: string, descriptor?: TypedPropertyDescriptor<INPUT>) {
const _propertyKeyClass = `_${propertyKey}Class`;
const _propertyKey = `_${propertyKey}`;
// const _propertyKeyClass = `_${propertyKey}Class`;
// const _propertyKey = `_${propertyKey}`;
if (descriptor) {
const set = descriptor.set!;
descriptor.set = function (val: INPUT) {
applyStyle(
createStyle(
this,
propertyKey,
_propertyKey,
_propertyKeyClass,
val,
style,
priority
Expand All @@ -308,41 +306,47 @@ export function Style<INPUT = any, C = any>(
};
if (!descriptor.get) {
descriptor.get = function () {
return this[_propertyKey];
return this[`_${propertyKey}`];
};
}
} else {
Object.defineProperty(target, propertyKey, {
configurable: true,
enumerable: true,
set(val: INPUT) {
applyStyle(
createStyle(
this,
propertyKey,
_propertyKey,
_propertyKeyClass,
val,
style,
priority
);
},
get() {
return this[_propertyKey];
return this[`_${propertyKey}`];
}
});
}
};
}

function applyStyle<INPUT, C>(
/**
* Create a style for component with a key
* @param c The component
* @param propertyKey Style key
* @param val value
* @param style style template
* @param priority priority of style
*/
export function createStyle<INPUT, C>(
c: WithStyles,
propertyKey: string,
_propertyKey: string,
_propertyKeyClass: string,
val: INPUT,
style: InputStyle<INPUT, C>,
priority?: number
) {
const _propertyKeyClass = `_${propertyKey}Class`;
const _propertyKey = `_${propertyKey}`;
const oldValue = c[_propertyKey];
c[_propertyKey] = val;
const styleTemplate = style(val as NonNullable<INPUT>, c as any);
Expand Down

0 comments on commit c492df1

Please sign in to comment.