@@ -30,32 +30,21 @@ const accessors = {
3030
3131} ;
3232
33- // Assign metadata to array elements
34- // data - array of objects
35- // metadata - data describes PrototypeClass structure
36- // Returns: built PrototypeClass
37- //
38- function assignMetadata ( data , metadata ) {
39- const proto = buildPrototype ( metadata ) ;
40- assignPrototype ( data , proto ) ;
41- return proto ;
42- }
43-
4433// Assign prototype to records array or single record
4534// data - array of objects
4635// proto - dynamically built prototipe to be assigned
47- //
48- function assignPrototype ( data , proto ) {
36+
37+ const assignPrototype = ( data , proto ) => {
4938 if ( Array . isArray ( data ) ) {
5039 data . forEach ( item => item . __proto__ = proto . prototype ) ;
5140 } else {
5241 data . __proto__ = proto . prototype ;
5342 }
54- }
43+ } ;
5544
5645// Build Prototype from Metadata
57- //
58- function buildPrototype ( metadata ) {
46+
47+ const buildPrototype = ( metadata ) => {
5948 const protoClass = function ProtoClass ( ) { } ;
6049 let index = 0 , fieldDef , buildGetter , fieldType ;
6150 for ( const name in metadata ) {
@@ -66,10 +55,23 @@ function buildPrototype(metadata) {
6655 if ( buildGetter ) buildGetter ( protoClass , name , index ++ , fieldDef ) ;
6756 }
6857 return protoClass ;
69- }
58+ } ;
59+
60+ // Assign metadata to array elements
61+ // data - array of objects
62+ // metadata - data describes PrototypeClass structure
63+ // Returns: built PrototypeClass
64+
65+ const assignMetadata = ( data , metadata ) => {
66+ const proto = buildPrototype ( metadata ) ;
67+ assignPrototype ( data , proto ) ;
68+ return proto ;
69+ } ;
70+
71+ // Usage
7072
7173// Define Data Source
72- //
74+
7375const data = [
7476 [ 'Marcus Aurelius' , 'Rome' , '212-04-26' ] ,
7577 [ 'Victor Glushkov' , 'Rostov on Don' , '1923-08-24' ] ,
@@ -79,7 +81,7 @@ const data = [
7981] ;
8082
8183// Define metadata to build prototype dynamically
82- //
84+
8385const metadata = {
8486 name : 'string' ,
8587 city : 'string' ,
@@ -93,7 +95,7 @@ const metadata = {
9395} ;
9496
9597// Define query using regular JavaScript syntax
96- //
98+
9799const query = person => (
98100 person . name !== '' &&
99101 person . age > 25 &&
0 commit comments