An object-driven, cross-platform JS programming framework, that uses behaviour-driven objects for abstract development.
OBJY can be used in Node and the Browser.
npm install objy<script src="https://cdn.jsdelivr.net/npm/objy/dist/browser.js">Programming on OBJY is done in two simple steps:
- Define an object wrapper (a bucket of objects) an choose how objects in this wrapper are stored, processed and observed.
- Build and handle objects and tell them what to do.
// Define an object wrapper
OBJY.define({
name: "object", // singular constructor name
pluralName: "objects" // plural constructor name
})
// OBJY now has the contructors:
OBJY.object() // as a wrapper for single objects
OBJY.objects() // as wrapper for multiple objects// Build an object
OBJY.object({
name: "Passport",
properties: {
expires: "2020-10-10",
number: "123"
}
})// Build an object
OBJY.object({
warnMe: {
date: "2020-10-05",
action: "email('expiring soon!')"
},
onChange: "if(this.number.length == 0) return;"
})// add one
OBJY.object({...})
// add multiple
OBJY.objects([{...}, {...}])// by its reference:
let myObj = OBJY.object({...});
console.log(myObj);
// or via the get method
OBJY.object(id).get(obj => {
console.log(obj)
});OBJY.objects({type:'example', 'properties.expired' : false}).get(objs => {
console.log(objs) // [{},{}]
});var myObj = OBJY.object({
name: "my object"
});
// Update directly
myObj.type = 'test';
// or use built-in methods
myObj.setProperty('name', 'our object')
.addProperty('open', false).// delete one
OBJY.object({
...
}).delete(callback);Naturally, OBJY objects life in the JavaScript instance. You can, however use customized or predefined persistence mappers.
Predefined from OBJY Catalog:
OBJY.define({
name: "object",
pluralName: "objects"
storage: new OBJY_CATALOG.mappers.storage.mongoDB('mongodb://...'),
})Custom mapper:
OBJY.define({
name: "object",
pluralName: "objects"
storage: OBJY.customStorage({
add: () => {},
getById: () => {},
...
})
})When using persistence, CRUD operations are done with:
// Add to persistence
OBJY.object({...}).add(obj => {})
// Get by id
OBJY.object(id).get(obj => {})
// Query
OBJY.objects({query...}).get(objs => {})
// Update (methods can be chained)
OBJY.object({...})
.addProperty('color', 'blue')
.setProperty('name', 'Test')
.save(obj => {})
// Delete
OBJY.object({...}).delete(obj => {})- Marco Boelling - Initial author - Twitter
This project is licensed under the MIT License - see the LICENSE file for details.
