mtmr0x / nucleo Goto Github PK
View Code? Open in Web Editor NEW๐๏ธโโ๏ธ Nucleo is a strongly typed and predictable state container library for JavaScript ecosystem written in TypeScript
License: MIT License
๐๏ธโโ๏ธ Nucleo is a strongly typed and predictable state container library for JavaScript ecosystem written in TypeScript
License: MIT License
We discussed about how to treat possible optional fields and/or null
fields and how Nucleo can work with that.
Right now Nucleo must receive data as expected, has no optional field (which is actually really coherent to its purpose) and does not accept null
as value or as possibility.
Making it easy, we have to decide two main things here:
Should Nucleo have optional fields? Why? And if yes, how?
Should Nucleo have a way to treat or understand somehow null
values? Why? And if yes, how?
I've missed of a function type to complement a given data model.
Well, this is going to be useful to have, organised by each patch in a simple way to organise the project needs.
Probably the best approach is how they're doing in Deno project, a simple file in the root of the repository.
As quoted in #9, Nucleo needs to give freedom to primitive/scalar types. This way Nucleo can receive contracts like this:
const ageRule = (value) => {
return value < 100; // you defined here that age can not be higher than 100
}
const userType = new NucleoObject({
name: 'user',
fields: {
name: NucleoString(),
age: NucleoString(ageRule)
}
});
The age
field will be validated by the rule the user sent.
It will demand:
In discussion with my friend Hugo Bessa, we spoke about how could I make sure a ISO date would be always a ISO date and creating other types might not be a great idea but what about my primitive type be custom somehow?
I know it's a number, but I can create rules for this number don't be greater than x or non-zero values
It must be a string, but is a specific type of string, as a only numeric string or not having spaces, validated by a regex, for example.
I really don't know if it's a good idea or not, but for now I would say to avoid entering cyclic objects in store for avoiding n
problems.
NucleoObjectType
fieldsWhen you call the cloneState method of a non-existent contract instead of receiving a undefined
value, the javascript throw a TypeError
as a invalid code.
So, as I said before, when you ask for a contract non-existent we need to receive something that does not stop the application, and that we can manipulate.
update
method is still quite bugged and not well tested. Improve tests and validations for make sure update
is mature.
Imagine the user want to save one specific field only and there is no need to re-save others. Could dispatch
be able to identify it somehow and save a single data?
Or maybe a update
function responsible for that?
considering the store value for userTest
is:
{
userTest: {
name: { firstName: 'John', lastName: 'Smith' },
age: 20
}
}
If we run:
update('userTest')({ name: { firstName: 'Joe' } });
we get this result:
{
userTest: {
name: { firstName: 'Joe', lastName: 'Smith' },
age: 20
}
}
When a listener be executed from inside Nucleo, increment in the object the new data being stored as copy.
indexSearch
;When you call a update function, and pass false
values like:
These values doesn't update the store, and return OK with the supposed new values.
When this situation happens, was verified in the indexSearch
, on rec
and save
methods inside dataReflection
that, the validation of these new values use a conditional OR
in javascript used like ||
and this don't let pass those false
values, as said before.
Every object in Nucleo must be a Nucleo Object Type.
NucleoObjectType
NucleoObjectType
Primitive types must be their architecture well defined for be able to storeTree assure the store contracts are aligned
Well, the problem consist in:
const user = update('user')({ name: { firstName: 'Robert' }});
data
value, as showed on documentation example:{
status: 'OK',
errors: [],
data: {
name: {
firstName: 'Robert',
lastName: 'Nor'
},
age: 27
},
}
I receive the same data
, that I used into update method as a parameter, in another words, I receive
{
status: 'OK',
errors: [],
data: {
name: {
firstName: 'Robert',
},
}
}
I've been thinking about create some immutable entries in some contract fields, what you guys think about create an Enum type that can be used by the contracts?
Contract is the Object Model for creating NucleoObject
s. Creating the store, every object passed must be a valid contract created with NucleoObject
;
instanceof
NucleoObject
;NucleoObject
dispatch
and subscribe
must be returnedWe should be able to create lists of NucleoTypes
and Lawyer function must validate it.
NucleoList
of NucleoString
NucleoList
of NucleoObject
Improve NucleoList
tests, exploring possible flaws using update
method
update
a list with primitive valuesupdate
a list with NucleoObject valuesupdate
values to a list not according to the list primitive type expectedupdate
values to a list not according to its expected NucleoObject typeThe Nucleo memory usage in saving data and sending information to listeners makes it possible, the only thing that is necessary to discuss and understand is how to make it and still provide performance and simple code.
Today we have:
update -> validations -> index state search with state clone -> save
In index state search with state clone
is possible store another copy that is easy to consult and can be send to listeners as new reference.
Lawyer is quite complex and tricky to understand, there is for sure a better way to make that code be better.
Dispatch is returning an error and it's not predictable considering how update works. For better error treatment, dispatch should return an error object for the developer treat errors nicely
It must create the storeTree and the store objects.
storeTree
architecture;storeTree
in memory;store
architecture;store
in memoryHaving subscribed as listener, it should provide a way to unsubscribe that listener.
PR: #33
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.