formidablelabs / biff Goto Github PK
View Code? Open in Web Editor NEWThis project forked from kenwheeler/mcfly
Flux architecture made easy
License: BSD 3-Clause "New" or "Revised" License
This project forked from kenwheeler/mcfly
Flux architecture made easy
License: BSD 3-Clause "New" or "Revised" License
You removed all the console behavior but missed a line in Store.js Line 15.
admittedly, I'm newer to the syntax of ES6 and ESNext but I am curious as to what Biff's syntax would be for creating stores?
export class SomeStore extends Biff.createStore{
_store = [];
addStoreItem(item){
this._store.push(item);
}
//etc...
}
That is the equivalent of what I have so far, but I can't seem to figure out how to add the dispatcher handler function to the class. Am I way off base and using class incorrectly, or does Biff not have support for ES6?
I've created a Store called RegistrationStore and added this to react component
RegistrationStore.mixin
The first time storeDidChange is called everything works as expected. I have a child component that calls the parent component when a button is clicked and I ran into this problem.
TypeError: _this.storeDidChange is not a function
at Store.mixin.componentDidMount.listener (Store.js:59)
at Store.EventEmitter.emit (events.js:99)
at Store.emitChange (Store.js:154)
at Store.<anonymous> (RegistrationStore.js:46)
at Store.<anonymous> (Store.js:14)
at Dispatcher.$Dispatcher_invokeCallback (Dispatcher.js:220)
at Dispatcher.dispatch (Dispatcher.js:195)
at Action.Biff.createActions.storeSectionFields [as callback] (RegistrationAction.js:41)
at React.createClass.onSectionSubmit (ModuleRegistrationComponent.jsx:88)
at React.createClass.submit (SectionComponent.jsx:56)
here is my onSectionSubmit
onSectionSubmit: function(model,transition){
var data = [];
this.state.fields.map(function(field){
if( model[ field._id ] ){
if( field.type === 'dropdown' ){
data.push( {_id : field._id, value : model[field._id].split(',') } );
}else{
data.push( { _id : field._id, value : model[field._id] });
}
}
});
// Here is where the error happens.
RegistrationAction.storeSectionFields( data );
},
This is my store and my action
var Biff = require("../biff");
var request = require("superagent");
var RegistrationAction = Biff.createActions({
checkEmail: function(data) {
var self = this;
request
.post("/users/create")
.send({ user : data})
.set("Accept", "application/json")
.set('Content-Type', 'application/json')
.end(function (error,res) {
console.log( res.text );
self.dispatch({
actionType: "REGISTRATION_CHECK_EMAIL",
data: JSON.parse(res.text)
});
});
},
getSectionFields : function( data ){
var self = this;
request
.post("/fields/get")
.send({ sectionId : data})
.set("Accept", "application/json")
.set('Content-Type', 'application/json')
.end(function (error,res) {
self.dispatch({
actionType: "REGISTRATION_FIELDS_GET",
data: JSON.parse(res.text)
});
});
},
storeSectionFields : function( data ){
console.log( "StoreSection" );
console.log( data );
this.dispatch({
actionType: "REGISTRATION_FIELDS_STORE",
data: data
});
},
setCurrentSection : function( module ){
this.dispatch({
actionType: "REGISTRATION_SET_SECTION",
data: module
});
}
});
module.exports = RegistrationAction;
var Biff = require("../biff");
var RegistrationStore = Biff.createStore({
_user: {},
_module: {},
_fields:{},
_enteredFields:[],
checkEmail: function (data) {
this._user = data;
},
getUser : function(){
return this._user;
},
setCurrentSection :function(data){
this._module = data;
},
setCurrentSectionFields :function(data){
this._module = data;
},
getCurrentSection: function(){
return this._module;
},
setSectionFields: function(data){
this._fields = data;
},
getSectionFields: function(){
console.log( "Getting section" );
console.log( this._fields );
return this._fields;
},
storeSectionFields: function(fields){
this._enteredFields.push( fields );
}
}, function (payload) {
switch( payload.actionType ){
case 'REGISTRATION_FIELDS_GET':
this.setSectionFields(payload.data);
this.emitChange();
break;
case 'REGISTRATION_FIELDS_STORE':
this.storeSectionFields(payload.data);
this.emitChange();
break;
case 'REGISTRATION_CHECK_EMAIL':
if( payload.data.error){
this.emitError( payload.data.error );
}else {
this.checkEmail(payload.data);
this.emitChange();
}
break;
case 'REGISTRATION_SET_SECTION' :
this.setCurrentSection(payload.data);
this.emitChange();
break;
}
});
module.exports = RegistrationStore;
So what's the difference between the two? Was Biff created simply so it can live under FormidableLabs? Will McFly continue to be maintained or is Biff now preferable?
How do I add multiple stores to a React component using ES6 syntax?
Building an application where there is a loader component which is shown until multiple stores have loaded. On each store update the component would look up if the store is ready by calling a store method. Could it be a bad practise to do so? Alternatives?
EDIT
For now just opted to add events manually by using MyStore.addChangeListener
in the MyComponent.componentDidMount
method, the same as the store mixing would do automatically.
May close this "issue"!
It would be nice to have the ability to snapshot the entire Flux setup on the server and then boot from the snapshot once the client loads up.
Switch from Jest to a Mocha/Sinon/Karma/Instanbul test setup.
Investigate whether
warn = (console.warn || console.log).bind(console)
introduces errors in IE8
It's gonna have to happen eventually. ๐
Getting error when doing a React.renderToString.
biff/node_modules/simple-console/simple-console.js: line 104.
Might need to change
_console = window.console || null;
to
_console = ( window && window.console ) ? window.console : null;
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.