Skip to content

Commit

Permalink
use lambda instead of this context
Browse files Browse the repository at this point in the history
  • Loading branch information
Gilad Gray committed Mar 15, 2017
1 parent 2d7e221 commit 3ce09f6
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/plugins/kss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class KssPlugin implements IPlugin<IKssPluginData> {

public compile(cssFiles: IFile[], dm: ICompiler) {
const styleguide = this.parseFiles(cssFiles);
const sections = styleguide.sections().map(convertSection, dm);
const sections = styleguide.sections().map((s) => convertSection(s, dm));
const css = dm.objectify(sections, (s) => s.reference);
return { css };
}
Expand All @@ -65,19 +65,20 @@ export class KssPlugin implements IPlugin<IKssPluginData> {
}
}

function convertSection(this: ICompiler, section: kss.ISection): IKssExample {
// using `this` arg to pass a "context" arg to these callbacks so they have access to some helper funcs
function convertSection(section: kss.ISection, dm: ICompiler): IKssExample {
return {
documentation: this.renderMarkdown(section.description()),
documentation: dm.renderMarkdown(section.description()),
markup: section.markup() || "",
markupHtml: this.renderMarkdown(`\`\`\`html\n${section.markup() || ""}\n\`\`\``),
modifiers: section.modifiers().map(convertModifier, this),
markupHtml: dm.renderMarkdown(`\`\`\`html\n${section.markup() || ""}\n\`\`\``),
modifiers: section.modifiers().map((mod) => convertModifier(mod, dm)),
reference: section.reference(),
};
}

function convertModifier(this: ICompiler, mod: kss.IModifier): IKssModifier {
function convertModifier(mod: kss.IModifier, dm: ICompiler): IKssModifier {
return {
documentation: this.renderMarkdown(mod.description()),
documentation: dm.renderMarkdown(mod.description()),
name: mod.name(),
};
}

0 comments on commit 3ce09f6

Please sign in to comment.