structurae
Advanced tools
Comparing version 3.0.1 to 3.0.2
@@ -7,2 +7,6 @@ # Changelog | ||
## [3.0.2] - 2020-04-02 | ||
### Added | ||
- MapView can use custom ObjectView classes to initialize nested objects. | ||
## [3.0.1] - 2020-04-02 | ||
@@ -9,0 +13,0 @@ ### Fixed |
@@ -335,2 +335,3 @@ // Type definitions for structurae | ||
static fields: string[]; | ||
static ObjectViewClass: typeof ObjectView; | ||
static Views: ViewTypes; | ||
@@ -350,3 +351,3 @@ | ||
export declare function MapViewMixin(schema: object, MapViewClass?: typeof MapView): typeof MapView; | ||
export declare function MapViewMixin(schema: object, MapViewClass?: typeof MapView, ObjectViewClass?: typeof ObjectView): typeof MapView; | ||
@@ -353,0 +354,0 @@ interface BinaryProtocolSchema { |
@@ -166,7 +166,7 @@ const { ObjectView, ObjectViewMixin } = require('./object-view'); | ||
static initialize() { | ||
const { schema } = this; | ||
const objects = ObjectView.getSchemaOrdering(schema); | ||
const { schema, ObjectViewClass } = this; | ||
const objects = ObjectViewClass.getSchemaOrdering(schema); | ||
if (objects.length > 1) { | ||
for (let i = objects.length - 1; i > 0; i--) { | ||
ObjectViewMixin(objects[i]); | ||
ObjectViewMixin(objects[i], ObjectViewClass); | ||
} | ||
@@ -181,3 +181,3 @@ } | ||
if (field.type !== 'array') { | ||
View = ObjectView.getViewFromSchema(field); | ||
View = ObjectViewClass.getViewFromSchema(field); | ||
} else { | ||
@@ -189,3 +189,3 @@ const sizes = []; | ||
} | ||
View = ArrayViewMixin(ObjectView.getViewFromSchema(field), field.maxLength); | ||
View = ArrayViewMixin(ObjectViewClass.getViewFromSchema(field), field.maxLength); | ||
let itemLength = View.getLength(sizes.pop()); | ||
@@ -220,2 +220,7 @@ for (let j = sizes.length - 1; j >= 0; j--) { | ||
/** | ||
* @type {Class<ObjectView>} | ||
*/ | ||
MapView.ObjectViewClass = undefined; | ||
/** | ||
* @type {Object<string, Class<MapView>>} | ||
@@ -229,6 +234,8 @@ */ | ||
* @param {object} schema the schema to use for the class | ||
* @param {Class<MapView>} [MapViewClass] an optional ObjectView class to extend | ||
* @param {Class<MapView>} [MapViewClass] an optional MapView class to extend | ||
* @param {Class<ObjectView>} [ObjectViewClass] an optional ObjectView class | ||
* to use for nested objects | ||
* @returns {Class<MapView>} | ||
*/ | ||
function MapViewMixin(schema, MapViewClass = MapView) { | ||
function MapViewMixin(schema, MapViewClass = MapView, ObjectViewClass = ObjectView) { | ||
const id = schema.$id; | ||
@@ -238,2 +245,3 @@ if (MapView.Views[id]) return MapView.Views[id]; | ||
Base.schema = schema; | ||
Base.ObjectViewClass = ObjectViewClass; | ||
Base.initialize(); | ||
@@ -240,0 +248,0 @@ MapView.Views[id] = Base; |
{ | ||
"name": "structurae", | ||
"version": "3.0.1", | ||
"version": "3.0.2", | ||
"description": "Data structures for performance-sensitive modern JavaScript applications.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
215638
5772