Giter VIP home page Giter VIP logo

discuss's People

Contributors

devinivy avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

isabella232

discuss's Issues

Is there a problem triggering actions from a store?

I look at actions/listeners as a publish/subscribe pattern and use actions wherever and in series if called for. Some flux implementations seem to have a problem calling an action from within another action. I have not had any issues doing Action -> Store -> Api.get -> Api.got -> Action -> Store -> Action -> Api.get -> Api.got -> Store -> Store.trigger. Do you see any problem using this pattern in reflux?

No Action files! another step in being super lazy.

Normally in reflux we have several Actions files, containing list of strings, and in the stores we add methods like: onSomeAction. we have to manually connect everything, and when we change the name of the Action we do it twice or more.
Usually, I don't share Actions between stores, and this duplication is really annoying.
So I came up with this:

function createStoreAndActions(storeObj) {

    function startWithOn(str) {
        return str[0] === 'o' && str[1] === 'n' && str[2].toUpperCase() === str[2]
    }

    var ActionStrs = Object.keys(storeObj).filter(startWithOn);
    let Actions = reflux.createActions(ActionStrs);

    if (storeObj.listenables) {
        if (Array.isArray(storeObj.listenables)) {
            storeObj.listenables.push(Actions);
        } else {
            storeObj.listenables = [storeObj.listenables, Actions];
        }
    } else {
        storeObj.listenables = Actions;
    }

    return {
        Store: reflux.createStore(storeObj),
        Actions
    }

}

the convention I've used is taking all methods starting with 'on' and having capital letter after that. Of course it's easy to implement any other convention (e.g passing to create an array of strings etc)
then I can just specify those methods, and an auto actions will be created.

let {Store, Actions} = createStoreAndActions({
    mixins:[...],
     onTestAction(){
       console.log('it is working with no explicit Action!')
    }
});

export {Actions};
export default Store;

and in Component:

import TestStore, {Actions as testActions} from '../Stores/TestStore';
var Component = React.createClass({
    render: function() {
        return (
          <div onClick={testActions.onTestAction}>click here to log from store</div>
        );
    }
});

Reflux For SAFARI

Hi ,

Is Reflux supports in SAFARI, I had seen in github page its only for firefox, chrome, IE, Opera.

Actions not causing immediate remote changes

The unidirectional dataflow makes perfect sense if user interaction always (or never, as in most tutorial examples) gives rise to remote changes. A typical case:

  • The user enters a value into a field, which triggers an action (e.g. CommentActions.setTitle(title))
  • The action makes a remote call, and upon success triggers the CommentActions.setTitle.completed(title) child action
  • The store listens through e.g. CommentStore#onSetTitleCompleted(title), and changes its state
  • A component is re-rendered reflecting the new state (e.g. state.title).

Another way to put this might be that every modification to the local store is mirrored by a change in the remote store. However, for various reasons, this is not always desirable. In a lot of situations, it makes sense to only call the server once editing is complete, e.g. upon pressing a "Save" or "Post" button.

I can see this happening in a multitude of situations. For example, without knowing the implementation details, it seems likely that when creating events on Facebook, all data (date, title, description, guest list etc.) is stored locally until the user hits the "Create Event" button.

It seems logical to introduce an action like CommentActions.postComment(), but that creates a difficulty: there is no obvious way for the action to access all the data that has been supplied and edited to that point, unlike the first case where each action is fed the data subject to change (e.g. the title).

The best way I've come up with so far is to make the component responsible for feeding the right data to the action. The local values are held in the store, and are thus accessible to the component through mixing in of state. When it's time for the final save, it's triggered by e.g. CommentActions.postComment(this.state.title, this.state.body, this.state.email, ...).

I suppose there are many solutions involving breaking the Flux flow (e.g. having the store calling actions) but I'm only interested in solutions that don't break the very basic principles behind the library :)

Selective handling of changes in store

I have created a generic autocomplete component which I am using in a form for add and edit operations.
I have a autocompletestore where I fetch the data and set the state.
Component defines the onautocompletestorechanged function and updates ita state. Auto complete is rendered accordingly. Now the problem is every time the store changes all instances of this component render the autocomplete which is not intended. I only want the autocomplete to render for the component in which I am typing. Please help.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.