Skip to content
This repository has been archived by the owner on Jan 25, 2024. It is now read-only.

Commit

Permalink
feat(sassoptions): create class for options interface
Browse files Browse the repository at this point in the history
  • Loading branch information
kwonoj committed Jul 10, 2018
1 parent df4916b commit 282dc85
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions src/interop/sassOptions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { log } from '../util/logger';
import { wrapSassContext } from './wrapSassContext';
import { wrapSassOptions } from './wrapSassOptions';

interface SassOptionsInterface {
/**
* Release allocated memory with created instance.
*/
dispose(): void;
}

/**
* @internal
*
* Interop interface to `sass_option*` api
* (https://github.com/sass/libsass/blob/master/docs/api-context.md#sass-options-api)
*
*/
class SassOptions implements SassOptionsInterface {
/**
* Raw pointer to `struct Sass_Options*`
*/
private readonly sassOptionsPtr: number;
/**
* Construct new instance of SassOptions.
*
* @param {ReturnType<typeof wrapSassContext>} cwrapCtx cwrapped function object to sass context api.
* @param {ReturnType<typeof wrapSassOptions>} cwrapOptions cwrapped function object to sass option api.
*
* Manual creation of this class is prohibited;
* Should use `context.options.create` static interface instead.
*/
constructor(
private readonly cwrapCtx: ReturnType<typeof wrapSassContext>,
private readonly cwrapOptions: ReturnType<typeof wrapSassOptions>
) {
this.sassOptionsPtr = cwrapCtx.make_options();
log(`SassOptions: created new instance`, { sassOptionsPtr: this.sassOptionsPtr });
}

public get precision(): number {
return this.cwrapOptions.option_get_precision(this.sassOptionsPtr);
}
public set precision(precision: number) {
this.cwrapOptions.option_set_precision(this.sassOptionsPtr, precision);
}

public dispose(): void {
this.cwrapCtx.delete_options(this.sassOptionsPtr);
log(`SassOptions: disposed instance`);
}
}

export { SassOptionsInterface, SassOptions };

0 comments on commit 282dc85

Please sign in to comment.