Basically will produce a WebSockets/Single Entry API that you can call:
{
"modelName": ['attributeName', 'attributeName']
}
and then the React will update the children.
Still I can't decide between the GraphQL
of facebook:
class MyComp extends React.Component {
getQuery() {
return `{
modelName: {
attributeName1,
attributeName2
}
}`;
}
}
var needThis = require('need-this').needThis; // or just null?
class MyComp extends React.Component {
getQuery() {
return {
modelName: {
attributeName1: needThis,
attributeName2: needThis,
attributeName3: needThis
}
};
}
}
var store = require('./store');
var needThis = require('need-this').needThis;
class MyComp extends React.Component {
constructor() {
this.bindQuery();
}
bindQuery() {
store.iNeed({
modelName: {
attributeName1: needThis
}
});
}
}
- ID is just a string. you can render it the way you want, but it must be unique for not having problems.
- All the data will be stored in
this.data
- Fucking simple implementation.
User.find(id)
will return a Promise: if there is something on the cache, it will provide it, but add a request to the dispatcher to grab a new copy. - 20ms between each request. so we'd request one time and then refresh the cache.
class User extends NeedThisModel {
id() {
return this.data._id;
}
}
class Point extends NeedThisModel {
id() {
return [this.data.x, this.data.y].join(",")
}
}
class Post {
id() {
return this.slug;
}
}
module.exports = needThis(Post);
// models/message.js
var store = require('../store'); // the only store
class Message {
id() {
return `${this.from}:${this.to}:${this.timestamp}`;
}
}
module.exports = store.needThis(Message);
// store.js
var NeedThis = require('need-this');
class MyStore extends NeedThis {
webSocketsURL() {
return "ws://localhost:8001/";
}
apiURL() {
return "ws://localhost:8001/";
}
}
module.exports = new MyStore();