I am currently developing my first Meteor project, and as the code basis is growing, I am unsure about using session variables/ the reactive programming approach correctly. For example, let's have a look at a form for editing a blog article. Before editing, I use Session.set("current_article", Articles.findOne(id)) to set the current article. When opening the article form, everything is populated correctly by using <input type="text" name="title" value="{{article.title}}">.
But the form is much more complicated than just displaying the title:
E.g. when the title or a tag changes, the text on right the right (a generated tweet message) updates while typing. To achieve this, I register a keyUp listener that sets Session.set("current_article", $.extend(Session.get("current_article"), {tweet: someMagicTweetGeneration()})). You might already notice that the way I am using Session variables causes rerendering the whole template.
So my question is: Does it makes sense storing more complex objects (like articles) into a session variable? This way saving the form is quite straightforward, but it obviously causes other issues. Should I split Session.get("current_article") into Session.get("current_article.title"), Session.get("current_article.tweet"), ...? Any other best practices?
You could use {{#isolate}}..{{/isolate}} blocks so that only bits of your template are re-rendered and not the entire thing, e.g with:
{{#isolate}}
<input type="text" name="title" value="{{article.title}}">
{{/isolate}}
So now when you change article.title only the bits inside this isolate block will be changed, and everything surrounding will be untouched.
You do have to re-render bits of the DOM that change, so the idea is to only re-render the bits that need to be redrawn.
As for the Session variables, try storing them in a manner where if you send out the variable to the DOM, to avoid sending one large object and instead send only the pieces that are required for a template.
E.g in the above you might have many things used in {{article}}, but you only use {{article.title}} in that bit of code, so it might be better to use only template. If you know you're going to use all of them then you might as well use nested objects.
I want to bet on meteor getting better and better, so we don't have to jump through those kinds of hoops. I imagine you already know about http://docs.meteor.com/#template_preserve.
I would suggest you try splitting the data into two distinct structures in the session, main and sidebar. Have each template react to only one or the other. That may even be a reasonable schema for your mongo collections.
I read something about optimizing that suggested you store ids in the session, rather than whole objects, then just findOne for the collection.
Is this a hypothetical problem, or are there symptoms you are bothered with?
Related
I'm trying to build a form in which you can dynamically add text inputs as required. I don't want to save anything until the person clicks 'save' so it's important that this is done without a db collection.
I came up with this solution (http://meteorpad.com/pad/zP8EGjigXASfFrXsF/Input%20Test) but I'm unsure if this is the correct approach or is there an easier way?
Most users probably don't need to directly use Tracker.Dependency anymore because there are now higher-level options that are are a bit easier to use. Here are two choices:
Client Collections
You can declare a client-side collection like:
InputOptions = new Mongo.Collection(null);
It will have all of the same behavior as a normal collection without trying to sync its data to the server. This is probably what you want. The only disadvantage is that the collection will be available to your whole application, so its reactivity is not isolated to a single template.
ReactiveVar
You can use either a ReactiveVar or a ReactiveDict and scope it to your template. This is a bit better than directly using Tracker.Dependency because you don't have to call changed all over the place. Overall the syntax is more cumbersome that a client-side collection, but you get the advantage of isolating the reactivity if you need more than one of them.
Lets try this explanation again...
I'm new to polymer (and getting back into web dev after a relatively long absence), and I'm wondering what the recommended approach might be to more closely manage object state while employing 2 way databinding. I am currently consuming rest API (json) objects. My question is if polymer keeps a copy of the original object before initiating updates to the bound object's properties/attributes...so one might be able to easily undo the changes? While allowing 2 way databinding to work its magic is often desired, there are cases where I'd like to prevent / delay changes to the object / DOM until the user approves the changes (say via the paper-dialog component for instance). I suppose one could make a temporary copy of the object and bind fields to that version, and then only persist the changes back to the source object upon user approval. In any case, I'd be interested to hear thoughts and see an example or two of recommended approaches (especially if I am off-track with my ideas!)
I suppose one could make a temporary copy of the object and bind
fields to that version, and then only persist the changes back to the
source object upon user approval
This.
Consider that view-models are essentially different from pure data-models (sometimes called business-data). Frequently, the differences are irrelevant and one can use them interchangeably. However, be aware of scenarios where the view-model is distinct (uncommitted user edits are a good example).
The notion of a field editor that requires approval from the user is purely UI/View oriented. Whatever data is managed in that modality is purely in the domain of the view, and fetches/commits to the business-data should be discrete.
I have this textbox in asp.net webform page used to enter a city. On entering some text it provides suggestions just like facebook does of matching results.
I tried these two methods to implement this.
I first used onTextChanged event and AJAX and found out it only works when the textbox loses focus. I wanted a solution to work as you type. Advantage of using this was that I could use a database and it would be fast, because no xml files will be transferred in the process.
2.I used ajax, clientside using js. But the problem is the xml containing cities, there states, country is a massive 30MB file. So, it was impossible to use it, so thought of making 26 small xml files of each alphabet out of that big one but still they would be big enough to actually use. So, now I am planning to use 26*26 files containing the cities with same first two alphabets but I think its ineffective way to do what I want.
Is there any other efficient way of accomplishing it?
The best way would be to use a database, if I could.
You need to use onkeypress and/or onkeyup events instead.
Did you know that there are plug-and-play auto-complete components out there that are free? For example http://jqueryui.com/demos/autocomplete/
Use JSON! It's much more compact. You'll probably save 30-40% on the size of that data.
Did you know that you don't need to pass the whole data set for that to work? You can have it live on the server (e.g. in the database, or cached on the webserver for faster access and less db traffic), and have clients only pull small set of data at a time, based on characters that they type. That JQuery UI AutoComplete supports that feature.
If you cannot use JQuery and JQuery UI (not wanting would be an unacceptable answer), then I'm pretty sure there are other free alternatives, including this one: http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/AutoComplete/AutoComplete.aspx
Is there a list somewhere that lays out all of the types of changes that can be made to an existing workflow service that would prevent existing instances of the original workflow from being re-loaded? For example, I recently made a small change to a custom activity (changed a condition in an "if" statement) and all existing workflow instances still load as normal. Now, in the past, I had removed a property on an object that the workflow uses, and when I tried to re-load a persisted workflow instance, it blew up on me.
Does such a list exist? Thanks!
As far as I am aware there isn't a list like that. You really should consider all changes as breaking. If you test thoroughly you will find a few exceptions but these will be mostly changing a single VB expression.
There is no such a list.
As far as I am concerned, you can change VB expressions always editing the .xamlx in a text editor. I say that, because in my case, sometimes the graphical editor (VS2010) changed the ids of the activities without introducing new activities (be carefull with this).
You can also change the whole internal code (not the inputs/outputs parameters) in code activities (.xaml). Because of that, it would be a good idea to put all the "high changeable" logic into code activities in order to be able to modify this logic avoiding problems with existing WF instances.
I seem to keep running into these complex show/hide scenarios in ASP.NET web forms where the logic goes "if Field A equals blah, and Field B equals blahblah, then Field C is shown/hidden/validated/whatever." Before I run off and start building custom validators and custom controls so I can more easily manage it in markup or backend code, are there any libraries or simpler solutions I'm missing out there in the wild? jQuery makes the job easier, but I get the feeling I could abstract a lot of what I'm wrangling with out into a more elegant solution.
All of the controls that are dependent on each other or could trigger events are my own custom controls already, so I get the feeling I could start writing a small framework to handle it like so:
<my:DynamicShowHide runat="server">
<PrerequisiteFields>
<PrerequisiteField ControlId="FieldA" Value="blah" />
<PrerequisiteField ControlId="FieldB" Value="blahblah" />
</PrerequisiteFields>
<DependentFields>
<DependentField ControlId="FieldC" />
</DependentFields>
</my:DynamicShowHide>
...that way if the Prerequisite values were both evaluated as true, the DependentField would show, and hide if not.
It seems (and feels) like I'm overengineering but I run into insanely large and complex decision trees like this more and more often. Anyone know of a better way or an existing library that does something along these lines?
out of interest, in which particular instances do the use of decision trees most prominently arise?
For instance, I am guessing it is in most cases with dynamic data (data retrieved from a DB). And say the common usage for it would be in forms (or questionnaires) - hard to say as you have supplied examples of the usage of decsiion trees.
If these are the cases, then would it not be nice to handle all the stuff in the DB and populate the controls in the browser dynamically? You can set all the dependantUpon, and ansewrLeadsTo in the database, and the possible answers, and type of input control to generate, and it would lead to a much cleaner solution.
Granted the initial setup would be hard, but in the longterm, consider flexibility and maintenacne, and it should be okay.