zandaqo / structurae

Data structures for high-performance JavaScript applications.
MIT License
694 stars 21 forks source link

TextEncoder is not defined - Examples not working #6

Closed autorTepatiki closed 4 years ago

autorTepatiki commented 4 years ago

The single first example is not working due to an undefined TextEncoder in the module. The original code, as follows.

workspace/structurae-demo/node_modules/structurae/lib/string-view.js:364 StringView.encoder = new TextEncoder(); ^

ReferenceError: TextEncoder is not defined at Object. (/mnt/c/users/u0165298/workspace/structurae-demo/node_modules/structurae/lib/string-view.js:364:26) at Module._compile (internal/modules/cjs/loader.js:776:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10) at Module.load (internal/modules/cjs/loader.js:653:32) at tryModuleLoad (internal/modules/cjs/loader.js:593:12) at Function.Module._load (internal/modules/cjs/loader.js:585:3) at Module.require (internal/modules/cjs/loader.js:690:17) at require (internal/modules/cjs/helpers.js:25:18) at Object. (/mnt/c/users/u0165298/workspace/structurae-demo/node_modules/structurae/lib/record-array.js:17:20) at Module._compile (internal/modules/cjs/loader.js:776:30)


const { ObjectView, ArrayViewMixin } = require('structurae');

class Person extends ObjectView {} Person.schema = { id: { type: 'uint32' }, name: { type: 'string', length: 10 }, };

// an array class for Person objects const PeopleArray = ArrayViewMixin(Person);

// create an empty array view of 10 Person objects const people = PeopleArray.of(10);

// create an array view from a given array const hitchhikers = PeopleArray.from([ { id: 1, name: 'Arthur' }, { id: 2, name: 'Ford' }, ]); const arthur = hitchhikers.get(0); //=> Person [14] arthur.toObject(); //=> { id: 1, name: 'Arthur' }

// set the first object data hitchhikers.set(0, { id: 3, name: 'Trillian' }); hitchhikers.get(0).toObject(); //=> { id: 3, name: 'Trillian' }

hitchhikers.toObject(); //=> [{ id: 1, name: 'Arthur' }, { id: 2, name: 'Ford' }]