VoliJS / Type-R

Reactive and serializable objects with transactional changes.
MIT License
51 stars 8 forks source link

Experimental alternate syntax for relations (to consider) #42

Closed gaperton closed 6 years ago

gaperton commented 6 years ago

All ownership modifiers should be replaced with functions like type( Ctor ).

We're keeping the Collection.Refs type so far.

These modifiers could be used in place of type(), and could potentially lead to better code in TypeScript.

@type( Collection.subsetOf( '~users' ) ).as users : Collection<User>
@subsetOf( '~users' ).as users : Collection<User>

@type( User.from( '~users' ) ).as user : User
@from( '~users' ).as user : User

@type( User.shared ).as user : User
@shared( User ).as user : User

In regular JS, it will lead to cleaner annotations as well

@define class X extends Record {
    static attributes = {
         s : subsetOf( '~users' ),
         r : from( '~users' ),
         sh : shared( User )
    }
}

It will lead to cleaner ownership semantic (type means aggregation). It could allow taking attribute metatype and change its ownership scheme. Also, it could allow for splitting relations to the separate assembly.

It should be implemented as primary mechanics at stage 1 with backward compatibility fallbacks.

gaperton commented 6 years ago

This stuff is really amazing. Need to think for an alternative name for from, though. recordFrom? takeFrom?

gaperton commented 6 years ago

takenFrom( '~users' )