Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice
So I'm going to start messing about with one of these MV* things for fun, and I've looked at sample code / tutorials for a few, and Ember makes a lot more intuitive sense to me, but all the chit-chat from all the skinny jeans kids on the internet seems to be about Angular. Is this just because of :google: and it's just the flavor of the month, or is Angular on it's way to becoming the jQuery of client side app frameworks?

Adbot
ADBOT LOVES YOU

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Skiant posted:

Ember and Angular are not the same thing.
These slides explain it way better than I could.

This is why I started learning Backbone the other day.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

enthe0s posted:

How did a comparison between Angular and Ember spur you into learning Backbone? Just curious since I also started picking it up recently.

Because after messing around with both a bit, i had this conversation with myself: "I like Ember more so I'll learn that, but it looks like angular is the runaway train, so maybe I should learn that, but Ember fits my way of thinking, so I'll go with that, but there's so much more angular stuff coming out so maybe....and what exactly am I trading off by picking one over the other anyway? gently caress it, Backbone does 95% of what I need and I can figure it all out in an afternoon. "

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Kobayashi posted:

I want to learn about testing, both unit and integration. Can anyone point me at a real low-level, in-depth introduction? Something like Todo MVC for Javascript testing. I get the idea, but I don't know where to start, or how to approach writing tests, or even how to integrate testing into my workflow. It would be nice to learn by example.

It might not be exactly what you are looking for, but I found the book Test Driven Development by Kent Beck a really read on the subject. TDD is a bit "heavy", but even if you don't adopt the methodology, I think it will get you thinking about testing "the right way" .

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

sharktamer posted:

I've had a look through this thread and online opinion and it seems that I have settled on the javascript framework I want to learn once I'm able to pick up javascript and a bit of jquery. The general consensus seems to be that ember is the one worth picking up. Having to put together all the separate components in backbone doesn't seem worth it (even though I favoured flask over django for this exact reason) and angular just seems a bit iffy in some of its design choices.

However, while I've settled on one in terms of actual design and usage, it does seem that angular might actually be the one to pick for a newbie primarily based on its community support and the learning resources out there. There doesn't seem to be anything close to egghead.io and the thinkster.io angularjs tutorial for ember. So should I perhaps learn angular over js just because of the resources? It does seem that learning one should help with picking up the rest anyway.

Or, learn Ember and document your experience, creating the resource the Ember community lacks. I'm starting on a series of articles called "Watch Me Try And Figure Out...." that is going to be Backbone / React, mainly because I learn best by explaining things to others, even if the "other" is a text editor / pretend readers.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

an skeleton posted:

Any clue why an angular filter would throw too much recursion errors into the console/firebug?

I'm going to go with too much recursion on that one. :downsrim:

Post code.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

more like dICK posted:

I "installed" angular by downloading the files and putting them in a 'static/js' directory in my project.

I feel like I don't understand Web 3.0 because apparently I was supposed to use Node.js and something called Bower to do this??

Yeah, it's getting pretty stupid. I started dicking around with React and was looking at some routers for it, and all the README files are basically "npm install butt-router-lol" and that's it. Nobody even bothers with ".. Or just copy this one file into your js directory" any more.

My favorite is the React-Flux-TodoMVC example (http://facebook.github.io/react/docs/flux-todo-list.html) Paragraph 2 is basically "grab react-boilerplate, and then do all the npm install crap to get started." Paragraph 3 is "Oh, btw, the settings in the boilerplate package.json file all need to be changed to work with this tutorial. Look at our package.json file and figure it out."

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice
React.js peoples: How do you do CSS transitions in React?

Say I have a bar graph type thing:

JavaScript code:
GraphThing = React.createClass({
  render: function () {
     var myStyle = {width: this.props.val + "%"};
     return ( <div className="barWrapper">
        <div className="bar" style={ myStyle } />
     </div>);
  }
});
And let us assume that said component has code that listens for an event that will change the val prop that is not shown here. This "works" in that when my event fires and the value is modified, the bar changes length, but I'd like to animate that transition via CSS. Is this possible? I'm aware of ReactCSSTransitionGroup but since I'm not using a class name (since the value is computed) I think I might be screwed.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Maluco Marinero posted:

If its just straight css transitions, even styles which are set in the style tag gets transitioned provided you're going from numeric to numeric -- no auto.

ReactTransitionGroup is for entering and exiting DOM elements where you need some frame by frame additions of classes in creation.

Pro tip: If you typo your class name in your SASS file, your CSS transitions don't work so well. Turns out it works just fine like you said with no TransitionGroup needed. Assuming you have the right class names.... :v:

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

sim posted:

Just wanted to say thanks for this. I've haven't worked with React yet, but I'd really like to. I've read multiple tutorials/introductions and while I understood the benefit, I never fully grasped exactly how it worked. This plain english description helped solidify it for me.

For some reason React took longer for me to "get" than the other Frameworks, I think partly because it's so simple, and there's so much magic voodoo that I kept thinking I had to be doing something wrong: "OK, now how will I inform this component 6 miles down my tree that it needs to update... (30 mins of scouring docs, tutorials, etc.) ...Oh, it just does it."


I've been cranking out little React-based stuff the last few days, and I'm about to try a "real" project using React and react.backbone to make a kanban board for the Asana project management app / tool. I'm quite impressed with it.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Subjunctive posted:

This is great.

If you can/ don't mind saying, what do you do at Facebook? Understandable if you don't or can't answer :)


I'm really grooving on React now, and found another Backbone "hook" for it that I like: https://github.com/magalhas/backbone-react-component

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Pollyanna posted:

So in Ember, why is it that we define things like:

code:
App.ThingRoute = Ember.Route.extend({
    model: function() {
        return thing;
    }
});
instead of like:

code:
App.ThingRoute = Ember.Route.extend({
    model: thing
});
where thing is assumed to just be a generic object? What's the point of passing in a function instead of just a reference to that object?

Because it is called so you can put logic in it.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice
Cross posting from the Screenshots thread...

I made a JSON viewer in React:



You can mess with it here: http://eskimospy.com/stuff/react/json/ and there's links to the source if anyone wants to use it and / or look over the code and tell me what incredibly stupid things I am doing since I'm still trying to figure out React for the most part.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice
I wrote a very basic blog post about mixins in react: http://simblestudios.com/blog/development/react-mixins-by-example.html

You can either hopefully learn something from it, laugh at my writing, or both!

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

HaB posted:

You sound like me when I first started using Angular.

Honestly - if you try to apply just about ANYTHING you learned in another language to Angular - it will be obtuse and annoying as poo poo. Until I finally embraced the "stop thinking in _________ and think IN Angular" concept, where ________ is whatever other language you know - which for me was basically any C-style language - I thought Angular was stupid and annoying as poo poo. Why? Why would anyone try to write a full MVC stack in Javascript? Javascript?!?? The language that pioneered the technique of giving you enough rope to hang yourself with, AND showing you how to tie the noose to boot?

Once I finally worked through some tutorials and really let go of everything else I knew - I understood the power/flexibility of it. And now I love it. But yeah - if you don't think in Angular, it sucks.

Even just off the top of my head - the ability to have an app up and running in minutes with writing almost ZERO boilerplate is amazing. Once you've used it long enough you wind up with little libraries of your own directives and things you can pull out as needed. It's awesome to be able to start a new app and before the end of the first day, you are writing the APP, and not still scaffolding or laying out architecture.

I think this nails why I'll never like Angular. Not because I can't make myself "unlearn" everything else, but because Angular demands I do so. When I can say "Oh, this is like ___ from ____, I get it!" in anything: a language, a framework, a game... I learn faster and can get to actually accomplishing things quicker, and that's the whole point of a framework. I imagine if my sole job was to write Angular, spending the time to think in it would be a good investment (possibly.) As someone who flits between languages and frameworks weekly, if not daily, "the Angular way" is overhead I can't afford.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

HaB posted:

you can hammer nails with a screwdriver handle, but it's not the best way to utilize the screwdriver. Or the best way to hammer nails.

Hmm, this could explain why so many of my home improvement projects turn out the way they do....



And I agree with your assessment about Angular. It's a very specialized tool that requires a lot of "training" to use. I wish I had time to focus on one thing that long... :supaburn:

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

fuf posted:

I tried this today but it's not quite what I was expecting. It really is for converting existing static sites, because each page needs to be a full html page with its own <head> and nav menus etc etc.

Really I want something that loads page snippets into my main index.html, and which also allows for routing so people can hit me.com/about etc. and get the right page. Anything lightweight that does that or should I stick with ember?

Check out React and react-router.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice
I came across this during my morning coffee: https://medium.com/este-js-framework/whats-wrong-with-angular-js-97b0a787f903

I've only the barest experience with Angular, so I have no idea if the points are all valid, but I thought it might generate some discussion.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice
I'm goofing around with a Django-Rest-Framework -> React/Flux "fun" project (you've inspired me, Thermopyle!) and just want to get some opinions on how people would approach something. The app shows a list of Activities. A user clicks on one, and the details for said activities are displayed. So far, so good! Users can also sign up for Activities, and here's where my question lies.

Given that part of the details for an Activity is a list of other people who have signed up for it and possibly some other info about those users, getting the details is far more resource heavy than just getting the name and start date for it, which is all that's shown in the list. Users will rarely click on more than a few Activities, and there might eventually be a "large" number in the list. One option is that I can get the full details of every Activity into a single store up front, and just use that for everything. Another option is two stores, one for the list, one for the details view, with the list store only getting a "light" version of the object containing just the fields it needs that don't traverse any relationships and the detail store doing the "heavy" queries for participants and so on for just one object at a time. The third option is probably the smart one that I haven't thought of yet.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Thermopyle posted:

I used to get hung up on this kind of stuff a lot more often.

Nowadays, I always get all of the things all of the time. I mean, it might be more resource heavy but I worry about that when it becomes an actual problem. Often it doesn't ever become a problem, and I saved myself the effort of additional code.

And by additional code I don't just mean the effort of writing more lines because that's barely anything. I mean the extra mental capacity taken up by having more logic to keep in your brain when reasoning about your code.

But I won't feel smart if I don't prematurely optimize! :smith:

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Thermopyle posted:

no

JavaScript code:
var App = React.createClass({
  render: function () {
    var searchResults;
    if (this.state.results) searchResults = <SearchResults results={this.state.results} />
    
    return (
       <div>
           <SearchForm />
           {searchResults}
       </div> 
    )
  }
});

This is another semi-similar way:

JavaScript code:
var SearchApp = React.createClass({
     handleSearch: function () {
        // do a thing that searches
        this.setState({  searchResults: theResults });
    },
    getInitialState: function () {
        return {searchResults: []};
    },
    render: function () {
        return (
	   <div className="getMeIAmAWrapper">
             <SearchForm />
             <SearchResults data={this.state.searchResults} />
	  </div>
        );
    }
});
That way SearchResults can decide to be empty, decide to be hidden, or show a "there are no results to display" message all on it's own depending on if it has data or not.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

an skeleton posted:

I have a question. I'm a novice developer (been seriously developing for about a year or so) and I am finally feeling pretty proficient in AngularJS (I still kinda suck at creating directives from scratch but whatever). I kind of have the itch to learn a new JavaScript framework, I was thinking Backbone or Ember. However, I have 2 questions.

1) Is there a real plus to learning to different frameworks or should I just keep at one and if I ever have a serious need for the other, switch over?

2) What would you use Backbone for that you wouldn't use Angular for? Like is there a specific type of application that just screams Backbone? (ditto for Ember, I guess)

Of course the real answer to my question 1 is "just do it and find out you dickhead, you're still a newb" but I'd rather listen to internet strangers' theories. Thanks!

1) Absolutely. You'll see different solutions to similar problems, which means your brain will have more ideas to draw from.

2) Everything, as I really don't like Angular. That is a personal thing though, as I know Angualr is a perfectly capable framework, it just has a different opinion on where and how things get done than I do.

I second Thermopyle's recommendation to look at React. For fun, learn Ampersand (https://ampersandjs.com) as well. It's a different take on Backbone, and looks pretty interesting.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

caiman posted:

So are CRUD operations common in an average Angular application? Or is that not what it's intended for?

Old way: browser sends POST request. Server does server things and assembles and returns a bigass new HTML page.

New way: javascript framework sends POST request. Server does server things and returns a smallish amount of JSON.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

TildeATH posted:

So I finally jumped into MVC and built a small app with Ember and Ember-CLI but, I don't know, it just seems too over engineered to me. I don't work on a big team, and for some reason I don't like the jQuery dependency and so I'm going to play around with React, which looks interesting. I'm a little leery of JSX, though, and prefer writing out the vanilla JavaScript. Does that make sense?

Sure, but JSX is pretty nice. Doing it in plain JS is certainly doable, but I've found JSX has grown on me quite a bit. Doesn't add any additional pains with jsx -w src/ dest so at least give it a try before dismissing it. React is really, really nice.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

HaB posted:

No worries.

And ha - no - I had to google "Canadian Provinces" to make sure Alberta was a province and not a city. So obviously I'm an American. :v:

Lair. A real American would have had to google to make sure Canada was a country.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Pollyanna posted:

I've actually have a bit of trouble reconciling React and Backbone/Ampersand/M-whatever. As I understand it, with React applications, you pass in data and receive rendered HTML:

JavaScript code:
var pollyanna = {
    name: "Pollyanna",
    age: 24
};

var Hello = React.createClass({
    render: function() {
        return (
            <div>
                <h1>
                    Hello, {this.person.name}!
                    You are currently {this.person.age} years old.
                </h1>
            </div>
        );
    }
});

React.render(<Hello person={pollyanna}/>, document.body);
If I were to, say, create a button that changed my name to uppercase when I clicked it, I would make a method like this:

JavaScript code:
    handleButtonClick: function() {
        var newName = "POLLYANNA";
        this.person.name = newName;
        // or, with a framework like Backbone:
        this.person.set('name', newName);
    },
However, this is apparently discouraged, since the React component has to know implementation details about the data storage/Model in order to modify it. So, React expects there to be some sort of event distribution system or somesuch in order for it to work properly. Which means you have to do something like this:

JavaScript code:
    handleButtonClick: function() {
        var newName = "POLLYANNA";
        EventDispatcher.trigger('nameChange', newName);
    }
where you now have to add at least one new method to your Model:

JavaScript code:
    registerCallback: function() {
        EventDispatcher.register(this.handleNameChange, 'nameChange');
    },
    handleNameChange: function(name) {
        this.set('name', name);
    },
The problem I see with this is that React really isn't a drop-in solution for a View layer at all. Using React means you have to restructure your application to use event dispatching, which if you're making something in Backbone or Ampersand is handled directly by the View and is therefore a core functionality of the framework. That's not easily changed. Not to mention that you still have to manually update your React component using forceUpdate() when your Model or Collection has changed - if React really is just "pass in data, get HTML out", how come it doesn't update itself when that data changes? It's bizarre.

You don't have a solid understanding of how React works, I suspect. Here is one way of explaining it:

  • A component renders itself.
  • If you have data you want rendered as part of it, you include it in that component's props.
  • Props should (in general) only come from a parent component.
  • If data is going to change, that change should take place in the state of the component that "owns" the data.
  • This means that the component who holds the data and is listening for changes to the data is not the one that renders the data.

So if my simple app has a list of things, my list is a child component of my top-level app component. List has a 'data' prop, which App sets:

code:
var App = React.createClass({
	getInitialState: function () {
		return {items: []}
	},
	render: function () {
		return ( <List data={this.state.items} />);
	}
});

var List = React.createClass({
	render: function() {
		var items = this.props.data.map(function (item) {
			return <li>An Item: {item.name}</li>
		});
		return (
			<ul>{items}</ul>
		);
	}
	// that's it! I don't know squat about the model, I just get a list passed into me
});
Then as the app runs:

  • App uses Ajax to fetch data from the server: it updates its own state with the new list.
  • App handles adding a new item. It updates its own state with the new list
  • App handles removing a new item. It updates it's own state with the new list.

And so on.

Every time App updates its state (specifically the items member) List will "see" the change automatically and re-render what it needs to without you doing anything.

Please note that App does not need to be the thing that actually makes the ajax call or process adding and removing. This could (and for anyting more complex probably should) be in some sort of model: either a Flux store, or a Backbone model, or whatever. Then App would be alerted that a change in the model happened and request the new list from the model, once again setting its state, which cascades down to List.

Here's A Thing™ on Backbone and React: http://timecounts.github.io/backbone-react/#1

Lumpy fucked around with this message at 15:28 on Jan 26, 2015

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Wheany posted:

Well of course I have, it's a weekday with a "d" in its name.

The good news is we can ignore this one as its bordering on 24 hrs old, so the new hotness should be coming out in a few minutes. I'm really excited about it, and am going to badmouth that thing I was very excited about last week and switch all my projects to it. I wonder what it will be called...

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

I hate how opinionated Aurelia was. IDFN lets me compose my app the way *I* want to without getting in my way.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice
To everyone learning React: your knowledge now has more use cases. Facebook announced React Native which lets one build native (not DOM-based) mobile apps in React: https://m.youtube.com/watch?v=7rDsRXj9-cU

Lumpy fucked around with this message at 13:21 on Jan 30, 2015

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice
I posted this in the Obj-C thread as well, but somebody with access to React Native posted a nice "first impression" piece: : http://jlongster.com/First-Impressions-using-React-Native

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Thermopyle posted:

I've been messing around with Reflux, and I think I like it better than vanilla Flux or Fluxxor.

It gets rid of the concept of the Dispatcher. Actions themselves become event emitters, and stores listen to the actions they're interested in.

Anyway, if anyone is having a hard time wrapping their head around Flux (which isn't terribly surprising as the pattern isn't quite as elegant as React itself), they might want to give Reflux a look.

Here's a blog post that does a bit of summary of the library: http://spoike.ghost.io/deconstructing-reactjss-flux/

I used Reflux on my last hobby project, and I very much liked it. There are definitely some things about "pure" Flux that make me scratch my head. That said, I'm not sure I have a better solution, just that I'm not convinced that is the "best" one.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

SpaceAceJase posted:

I want to jump into React, but should I bother using JSX or does everyone just ditch it?

Another "I like JSX" person here. It's so much more concise and declarative, which is the whole point of React.

Speaking of React, I watched the react-router talk from ReactConf this AM. Good stuff!

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

The Wizard of Poz posted:

Disclaimer: Please read the following with the understanding that I'm a bit naive/new to modern client-side development stuff (node, react, npm, requireJS etc) but I'm pretty experienced with web development in general. In other words, it's the tooling that I'm having trouble understanding - what to use, how to use it etc.

:words:

The problem here, I think, is obvious. I can't access any of those global variables (React, TodoList) because they are built into modules using watchify, so they are actually privately scoped variables by the time this inline script is run. It seems like I would need some parent module that is loaded on every page, looks for the containers, and inserts the appropriate React component - is that correct? It seems icky, and I'm starting to become incredibly disheartened because I feel like I just don't get it.


Think of each page you serve up as module. You build a script file for each, and include that.


JavaScript code:
// TodoPage.js
React = require('react');
TodoList = require('./TodoList');

var whut = {lol: "buttes"};
React.render(<TodoList config={whut} />, document.body);


// FriendsListPage.js
React = require('react');
FriendsList = require('./FriendsList');

var whut = {whee: "whoa"};
React.render(<FriendsList config={whut} />, document.body);
You then use browserify or whatever to make separate todo_bundle.js and friends_bundle.js out of those two files and include them on Todo.html and Friends.html respectively.

Obviously this assumes you have a multiple "page" app that gets a different set of functionality / React components on each. Remember that you can ignore React itself in the browserify / bundling process, and include it separately via a CDN or whatever to avoid having a bunch of bundles with React stuffed in them.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice
Semi-relevant to is thread: React Native is public: http://facebook.github.io/react-native/

I for one, am giddy with excitement. :banjo:

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Thermopyle posted:

I haven't been following this too closely. What's the word on Android?

Not in this first public release, but from what I remember from reading all about it after ReactConf, Android will be a 1st class citizen as well.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

mpaarating posted:

You're probably right. Oh god, I'm probably at the top of one of these curves right now.



Here's my version of that graph:

Only registered members can see post attachments!

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Stoph posted:

The best part is that many Google engineers have expressed desire to use React.js instead of Angular but they can't because of insane bullshit like the React.js PATENTS file:

https://github.com/facebook/react/pull/3554

One commentor mentioned their company's lawyers cleared that the code is licensed as BSD so they could just fork React.js and remove the file... :psyduck:

Looks like that may have changed?

https://code.facebook.com/posts/1639473982937255/updating-our-open-source-patent-grant/

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

enthe0s posted:

I'm trying to attach an event handler to each of my Tile components in React. This is exactly how the docs say to do it, but I get "Uncaught TypeError: Cannot read property 'bind' of undefined" when I try this. What am I doing wrong?

code:
...
Found it. I forgot to pass along *this* which I have now put into the original code.

Actually, I have a different problem now. The code runs, but nothing's happening when I click on a tile. I have some other click handlers that are on the Tile component which fire off just fine, but the one bound to the TileList isn't doing anything...

Post a fiddle with your current code, as it will help us help you immensely.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

enthe0s posted:

https://jsfiddle.net/69z2wepo/6685/

I left out some stuff I don't really think is relevant, but I can edit and include them if necessary.

You never set an onClick on your TileList, so no click on it is handled. I'm not sure if that's what you mean though. Also, I'm on my phone now so I might be missing something :v:

Your code seems very "un-React-like". There is a ton of logic in the tile, when it probably just wants to be a dumb view that calls whatever was passed to it as an onClick and that's it. The state of the game should live in a single place, so Tiles know nothing about it at all.

Lumpy fucked around with this message at 22:51 on Apr 19, 2015

Adbot
ADBOT LOVES YOU

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

enthe0s posted:

Yeah this is my first project with React, so it's very messy. I originally was going to have each Tile remember its state, but then I realized after going down that route that it doesn't make sense since I have to manage the state of 2 tiles to see if they are a match. So now I'm trying to get the TileList to manage the state with these click handlers.

I don't think I need to attach an onClick to the TileList itself. My thinking is that each Tile should have an onClick, which sends some info to the TileList so that it can manage the state of different Tiles. That's why I gave each Tile an onClick (line 50) and I thought that it would be handled by the onClick function defined on line 34. Isn't that what's happening in the example in the docs? https://facebook.github.io/react/tips/communicate-between-components.html

e: new page so here's the fiddle again so you don't have to go back and forth: https://jsfiddle.net/69z2wepo/6685/

Gotcha. Here's a pared down version of your code where the Tile objects call their own _handleClick and check to see if they got something to call from their parent. If so, they call it, passing all their data back up: https://jsfiddle.net/69z2wepo/6789/

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply