Hi,
I want to split the js code of the MainView in different files but i don’t know how to access an Observable list on the second file from the main one:
The mainPager.loadFeeds(); gets called but it only shows the “console.log(”…")" the observable is not shown but it works when called from the page (clicking on the button). How should i do it?
MainView.ux:
<App>
<JavaScript>
var Observable = require("FuseJS/Observable");
var mainPager = require("mainPager.js");
var uxbLogged = Observable(false);
function onLoginClick(){
uxbLogged.value = true;
mainPager.loadFeeds();
}
module.exports = {
onLoginClick: onLoginClick,
uxbLogged: uxbLogged
}
</JavaScript>
<PageControl ux:Name="LogginPager">
<Page ux:Name="LoggedOut">
<StackPanel Background="#fff">
<Text Value="Loggedout page"/>
<Button Text="Login!" Background="#f0f" Margin="20">
<Clicked Handler="{onLoginClick}"/>
</Button>
</StackPanel>
</Page>
<Page ux:Name="LoggedIn">
<ux:Include File="MainPager.ux" />
</Page>
<WhileTrue Value="{uxbLogged}">
<Set LogginPager.Active="LoggedIn"/>
<Callback Handler="{loadFeeds}"/>
</WhileTrue>
<WhileFalse Value="{uxbLogged}">
<Set LogginPager.Active="LoggedOut"/>
</WhileFalse>
</PageControl>
</App>
MainPager.ux:
<DockPanel>
<JavaScript File="mainPager.js" />
<PageControl Active="{pageControlActivePage}">
<Page ux:Name="newsFeedPage">
<Router ux:Name="routerNews" BackButtonAction="None"/>
<Navigator>
<Page Name="newsFeedsMainPage">
<StackPanel Background="#f0f" ux:Name="main">
<Text Value="This is the news feeds page"/>
<Button Text="Load feeds" Background="#00f" Margin="20">
<Clicked Handler="{loadFeeds}"/>
</Button>
<ScrollView>
<StackPanel>
<Each Items="{uxFeedsPageResults}">
<StackPanel Margin="5" Background="#EEE">
<Text Value="{user}"/>
<Text Value="{data}"/>
<Text Value="click here for more info"/>
<Clicked Handler="{onFeedClicked}"/>
</StackPanel>
</Each>
</StackPanel>
</ScrollView>
</StackPanel>
</Page>
<ProfilePage ux:Template="profilePage" router="routerNews" />
<DataPage ux:Template="dataPage" router="routerNews" />
</Navigator>
</Page>
<Page ux:Name="friendsPage">
<Router ux:Name="routerFriends" BackButtonAction="None"/>
<Navigator>
<Page Name="aaa">
<StackPanel Background="#0ff">
<Text Value="Page2"/>
<Button Text="Go to profile" Background="#fff" Margin="20">
<Clicked Handler="{page2Click}"/>
</Button>
</StackPanel>
</Page>
<ProfilePage ux:Template="profilePage" router="routerFriends" />
<DataPage ux:Template="dataPage" router="routerFriends" />
</Navigator>
</Page>
</PageControl>
<Panel Dock="Bottom" Height="100">
<Grid ColumnCount="2">
<Rectangle Background="#000">
<Stroke Width="2" Color="#fff"/>
<Text Value="Feeds" TextColor="#fff" Alignment="VerticalCenter" TextAlignment="Center"/>
<Clicked>
<Callback Handler="{tab1Clicked}"/>
</Clicked>
</Rectangle>
<Rectangle Background="#000">
<Stroke Width="2" Color="#fff"/>
<Text Value="Profiles" TextColor="#fff" Alignment="VerticalCenter" TextAlignment="Center"/>
<Clicked>
<Callback Handler="{tab2Clicked}"/>
</Clicked>
</Rectangle>
</Grid>
</Panel>
</DockPanel>
mainPager.js:
var Observable = require("FuseJS/Observable");
var pageControlActivePage = Observable("newsFeedPage");
var uxFeedsPageResults = Observable();
function onFeedClicked(sender){
var textToShow = sender.data.user + " " + sender.data.data;
routerNews.push("dataPage", {text: textToShow});
}
function loadFeeds(){
console.log("loading feeds");
uxFeedsPageResults.clear();
uxFeedsPageResults.add(
{user: "user1",
data: "data1"});
uxFeedsPageResults.add(
{user: "user2",
data: "data2"});
uxFeedsPageResults.add(
{user: "user1",
data: "data3"});
}
function tab1Clicked(){
pageControlActivePage.value = "newsFeedPage";
}
function tab2Clicked(){
pageControlActivePage.value = "friendsPage";
}
module.exports = {
tab1Clicked: tab1Clicked,
tab2Clicked: tab2Clicked,
pageControlActivePage: pageControlActivePage,
onFeedClicked: onFeedClicked,
uxFeedsPageResults: uxFeedsPageResults,
loadFeeds: loadFeeds
}