crcn / caplet.js Goto Github PK
View Code? Open in Web Editor NEWUniversal models library
License: MIT License
Universal models library
License: MIT License
holds a reference to a value
var ref = caplet.reference(user, "messages");
ref.watch(function() {
console.log(ref.value); // messages
});
ref.set("value", "blah");
console.log(user.messages); // blah
var Person = Caplet.createModelClass({
shouldLoad: function() {
},
fromData: function(data) {
return {
friends: People({ person: this })
}
}
});
load self if missing properties
similar to https://github.com/mquan/cortex/
This can be done in other libraries such as crudlet
var Person = Caplet.createModelClass({
mixins: [
Caplet.mixins.virtuals({
friends: function(onLoad) {
}
})
]
});
// or
var Person = Caplet.createModelClass({
initialize: function() {
Caplet.setVirtuals(this, {
friends: function(onLoad) {
}
});
}
})
collection.create(props, { waitUntilEvent: "didSave" });
Caplet.ssavet(target, create, update);
var Person = Caplet.createModelClass({
initialize: function() {
Caplet.setVirtuals(this, {
friends: function(onLoad) {
}
});
},
load: function(onLoad) {
return Caplet.memoize(this, "request", function(onLoad) {
return this.reload(onLoad);
});
},
reload: function(onLoad) {
// call loader if UID exists
return Caplet.load(this, onLoad, function(onLoad) {
$.get("/api/person", onLoad);
});
}
})
var User = caplet.createModelClass({
didDataChange: function(data) {
this.setProperties({
friend: User({ data: data.friend })
});
}
});
this needs to work:
Caplet.createModelClass({
mixins: [Caplet.watchModelsMixin],
getInitialState: function() {
return {
pages: models.pages
}
},
render: function() {
return {
'home': <Home />
'contact' <Contact />
}[this.state.pages.get("app")]
}
})
should re-watch models on re-render
var friends = caplet.recycle(this.friends, Friends, { data: data.friends });
crud.update(this, db.collection("people"), api.route("/people"));
serve models to front-end
something like
model.getAsync("property").then(onLoad);
caplet.createCollectionClass({
createModel: caplet.copyProperties(caplet.factory(caplet), "user")
});
var ChildModel = Model.extend({
initialize: function() {
this.once(this, this);
},
"missing:friends": function() {
this.set("friends", []);
}
});
var m = new ChildModel();
var friends = m.get("friends"); // []
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.