plastikfan / jaxine

Another JSON to XML converter with inheritable attributes and custom element consolidation
MIT License
0 stars 0 forks source link

Create ability for client to specify more options via Spec object #2

Open plastikfan opened 5 years ago

plastikfan commented 5 years ago

converter.buildElement accepts a getOptions calback which returns the build options. The build options currrently allows for only id, recurse and discards. Options needs to be expanded to allow further customisations eg the name of the _children, element name(_) attributes plus others.

plastikfan commented 5 years ago

Branch: build-with-spec

plastikfan commented 5 years ago

The new function "validateSpec" has to be called for every element. This seems onerous and unnecessary. R.memoizeWith, only works for primitive types so in order to memoize based on an object, you need to hash it. But hashing an object might be even more onerous than invoking the validation. There are two solutions, 1) just validate the spec for every build of an element (the overhead might not be that significant). 2) Just expose the validation function and let the client perform the validation. For now, we'll use the latter, since it is overbearing to run the check on an object which is essentially static for the lifetime of the client application.

plastikfan commented 5 years ago

Added indexBy tests, but it has occurred to me that releasing an object with unsatifactory implementation is not right. Although the current implementation which uses Ramda indexBy behaves consistently, it does create 'undefined' entries in the for those children that don't have attributes used for the key. A new implementation is required that only performs the indexBy if all children satify the condition of the indexBy invocation.