I have two pages/Template,
Dashboard (contains some User specific data as well).
Users.
I am using Meteor 1.5 with Blaze Template. Landing Page is Dashboard. I am using the common subscription for Collection Users in both Templates.
Scenario 1
When I use Meteor.subscribe('Users') in Dashboard's template.onCreated() and go to Users page, I see some already subscribed data coming back from Dashboard's subscription.
CODE:
Template.DashBoard.onCreated(function(){
Meteor.subscribe('Users');
});
Template.Users.onCreated(function(){
Meteor.subscribe('Users');
});
Scenario 2
When I use this.subscribe('Users') in Dashboard's template.onCreated() and go to Users page, I get a Fresh Subscription happening here and no data carry over from Dashboard's subscription.
CODE:
Template.DashBoard.onCreated(function(){
this.subscribe('Users');
});
Template.Users.onCreated(function(){
this.subscribe('Users');
});
Question
What is the difference between Meteor.subscribe('Users') and this.subscribe('Users') ? What can be the impact of using this.subscribe('Users') ?
As explained in Meteor documentation, this.subscribe within Template code will be automatically unsubscribed when the template instance is destroyed.
Whereas Meteor.subscribe needs to be explicitly unsubscribed if you want it to.
The decision to use one or the other depends on your app structure. If you are sure the data is relevant only for a given template, then use template scoped subscription, i.e. this.subscribe.
If the data is used across several pages, either use the "global" form, or scoped at a higher template level (one that persists through your pages, e.g. on layout).
Related
I have a page which allows a user to update a record, lets call it /edit-record, I want to support /edit-record/1 as a route which would load the data (I tried using getInitialProps) but I also want to make it so /edit-record is a page (ideally the same page) but without the API call to fetch the details happening.
So if I pass /edit-record/3 it should fetch record 3, if the url is /edit-record it just awaits user events.
The issue being I tried a conditional in getInitialProps, a if(query.recordId) {} but the else clause returns a null which NextJS doesnt like; it also just feels a bit wrong in terms of the approach.
What is the better way? Ideally I don't want to create two page files to handle the two conditions as all of the logic is the same.
I'm working on a project where I've been asked to show an alert in the "Account" form that notifies our users that an active record exists in a custom entity.
From the reading I have done so far I can see that
Xrm.Page.ui.setFormNotification('Message here', 'WARNING') appears to have the exact functionality that I need, but, how do I go about implementing the logic that shows this message. Presumably I need to do a count of associated records in this entity and if it's > 0 then show the alert, but, do I need to do this via a plug-in or is it Jquery? Or, am I vastly overcomplicating the issue when there is OOB functionality that will do this?
Any advice appreciated!
Adam
If your custom entity is a sub grid on the account form you can do this using JavaScript.
var count = Xrm.Page.getControl("custom_grid").getGrid().getTotalRecordCount();
if(count > 0) {
Xrm.Page.ui.setFormNotification('Message here', 'WARNING')
}
If its not a sub grid you will need to perform an API call to count the number of related records, you are best using the Web API, Use Microsoft Dynamics CRM web services.
The standard functionality you have at your disposal is roughly:
Workflows
Plugins
Business Rules
JavaScript
Of these options, only JavaScript currently supports setting form notifications. As a side-note, Business Rules do support showing error messages on specific fields (corresponding to setNotification from JavaScript).
You are thus correct that you would write JavaScript that determines whether the related records exist, and subsequently calls setFormNotification.
I work on a webapp with a workspace, where the user can create, load, and edit documents. This workspace is built with several areas, each taking care of a part of the job. A set of document loaded in a workspace is called a "project" and is stored in a "project" collection.
The data involved in a project is of two types:
the set of documents attached to the project. It is stored in the mongo document in the "project" collection
the current document a specific user is working on. I do not store it yet, I just use a set of global reactive variables to load a document and the attached informations when a user click on it. It means every time a user access to the workspace/project, he will not find the previously loaded documents but no documents loaded at all.
I now want to store the second type of data with one major requirement: to allow the user to work in an "extended mode" where one of the panels is in a dedicated browser window (supposedly on another screen). It means that if he clicks on a document in a window, the document is loaded in the other window/screen.
As far as I know, I can't send information directly from one browser window to another. I have to use the server to relay the information. So the user clicks on a document > the new loaded document id is sent to the server > the other window update accordingly.
Is my assumption correct? (the server must relay the info)
To implement this feature, I figured out a couple of solutions:
I attach a "project" field to the user profile mongo document. In each of these fields, I will have the last items loaded for each project and I will use this field to update one screen from the other.
I create a specific field in each project document where, for each user who worked on the project, I store the currently loaded document and its settings.
The first option suppose to load every project information along with the user profile (i.e. in every page) and could lead to send many times useless informations.
The second option will trigger the meteor reactivity mechanisms each time a user loads an item (without actually modifying the project) for every user connected to the project.
Each option has serious downsides, and I would like to know which one seems to be the better to you and if you can think of other alternatives.
You ought to be able to use one of the reactive local storage packages for Meteor especially if you are not concerned about not supporting non-HTML5 browsers... Can't give a massive amount of guidance on what one having not used most of them but the HTML5 local storage is usable across tabs and seems like a good place to store your data without a round trip to the server whilst also allowing it to persist between tabs.
You could also roll your own implementation (may be simpler than trying to find a package to match your needs exactly) by adding a listener to the app for local storage setitem() and removeItem() events as per this helpful guide from which the below code has been shamelessly copied...
if (window.addEventListener) {
// Normal browsers
window.addEventListener("storage", handler, false);
} else {
// for IE (why make your life more difficult)
window.attachEvent("onstorage", handler);
};
function handler(e) {
console.log('Successfully communicate with other tab');
console.log('Received data: ' + localStorage.getItem('data'));
//Add in your code to display the document on the second tab
}
localStorage.setItem('data', 'hello world');
What is the intended reactive behaviour when adding a document to a published collection? More specific: does adding a document to a collection invalidate all subscriptions to that collection (even those that are not matching) and result in a re-rendering of all dependent ui elements?
That's what I'm experiencing right now, at least.
To be even more specific: I have forms, with some "normal" fields but also lists. Those lists contain subforms which contain fields as well. Both types of forms are stored in a single generic Data collection. The view on this Data collection is managed with fine-grained subscriptions.
When I add a new list element, a new subform to the base form, the whole base form is re-rendered. Even none related base forms are re-rendered.
I have a github repo showing this, a little obfuscated though. It's a movie database. You can add a movie, give it a name, a tagline and add actors to the movie. An actor has a name and a home. When adding an actor to a movie every movie is re-rendered.
https://github.com/Crenshinibon/fields3/tree/462a9291bfc400a2731c21d2debdd4071be764ed
I'm aware of this question: Understanding Meteor Publish / Subscribe and think this part is actually missing. (I just don't have enough reputation points to ask in the comments) I understand the Pub/Sub mechanism of Meteor pretty well, I think. Just the resulting reactive behaviour is a little bit unclear.
I'm also aware of this question: Reactivity, isolation, and lists. But it's for Spark and Blaze changed a lot (especially, it made #isolate obsolete.)
And before I rebuild my app (again) to put all kinds of forms (or even properties) in different collections to avoid the "whole page" of being reloaded, I thought I might ask and maybe there is something I'm missing.
I'm on 0.9.0-rc10.
You should not put the subscribe calls in Meteor.autorun.
Meteor.autorun is a reactive context, meaning everything inside will get re-run if a reactive data source changes inside. We’re storing the channel we’re in inside the Session under "current_channel". If that session value changes, then the subscription is renewed and we have access to different messages!
src
Instead do something like this in your javascript:
Template.viewContent.movies = function () {
var subscription = Meteor.subscribe('movies');
return {
data: Movies.find(),
ready: subscription.ready
};
}
Then your template will look like this:
{{#each movies}}
{{#if ready}}
{{#each data}}
#DOSOMETHING WITH THE MOVIES#
{{/each}}
{{else}}
!!!Loading indicator here!!!
{{/if}}
{{/each}}
I am creating a movie timeline app with custom actions "Watching" but I want to use objects from imdb.com website.
Is this scenario supported? Do these objects must reside under my website?
That's possible.
Add the built-in watch action and movie object to your app and post to /me/video.watches with movie=http://www.imdb.com/title/tt0499549/ (example URL)
But at the end Facebook needs to check/approve your concept...
Yes this is possible as long as the action you're posting can be attached to the object type specified at the third party URL.
However, im not sure why you'd want to do this. Publishing an action to IMDB (for example) means friends of the user who published the story will end up on IMDB, not your app. But its your call...