Permalink
Browse files

widgets from loader.widgets removed if not in DOM anymore

  • Loading branch information...
1 parent 2fe2702 commit 7a16cc77901404b23b56b64b4573b3f02a9813ae @valentinzberea valentinzberea committed May 26, 2012
View
@@ -0,0 +1 @@
+*.DS_STORE
View
@@ -5,6 +5,11 @@ App.DataSourceConfig = {
'/todos': {
type: 'relational',
collection: 'todos'
+ },
+ '/news': {
+ type: 'relational',
+ collection: 'news'
}
+
},
-};
+};
View
@@ -3,13 +3,17 @@ var App = App || {};
App.main_modules = _.extend(App.main_modules, {
// Backbone Model + Collection
'model/todo': 'modules/todo_model',
+ 'model/news': 'modules/news_model',
'collection/todos': 'modules/todo_collection',
+ 'collection/news': 'modules/news_collection',
// Widgets
'widget/todo_list_widget': 'modules/todo_list_widget',
'widget/todo_widget': 'modules/todo_widget',
'widget/todo_add_widget': 'modules/todo_add_widget',
+ 'widget/news_list_widget': 'modules/news_list_widget',
// Controllers
- 'controller/TodoPage': 'modules/todo_page_controller'
-});
+ 'controller/TodoPage': 'modules/todo_page_controller',
+ 'controller/NewsPage': 'modules/news_page_controller'
+});
View
@@ -10,4 +10,8 @@ App.urls = {
'controller': 'TodoPage',
'layout': 'templates/todo_page.hjs'
},
-};
+ 'news': {
+ 'controller': 'NewsPage',
+ 'layout': 'templates/news_page.hjs'
+ }
+};
View
@@ -492,4 +492,4 @@ define ['cs!channels_utils', 'cs!module', 'cs!layout'], (channels_utils, Module,
if @never_rendered
@never_rendered = false
pipe = loader.get_module('pubsub')
- pipe.publish('/new_widget_rendered', @params['widget_id'])
+ pipe.publish('/new_widget_rendered', @params['widget_id'])
View
@@ -9,9 +9,17 @@ define ['cs!module'], (Module) ->
constructor: ->
widgetCheckInterval: 50 # ms
+ checkIntervalForRemovedWidgets: 1000
initialize: =>
setInterval(@checkForNewWidgets, @widgetCheckInterval)
+ setInterval(@checkForRemovedWidgets, @checkIntervalForRemovedWidgets)
+
+ checkForRemovedWidgets: =>
+ for widget_id of loader.widgets
+ if $("[data-guid='#{widget_id}']").length == 0
+ loader.widgets[widget_id].destroy()
+ delete loader.widgets[widget_id]
widgetCanBeStarted: (params) =>
###
@@ -68,4 +76,4 @@ define ['cs!module'], (Module) ->
$(el).removeClass('uberinitialized')
)
- return WidgetStarter
+ return WidgetStarter
View
@@ -10,5 +10,18 @@ var Fixtures = {
task: 'feed that damn dog'
}
]
+ },
+ news: {
+ responseText: [
+ {
+ id: 1,
+ newsText: 'great'
+ },
+ {
+ id: 2,
+ newsText: 'best feed that damn dog'
+ }
+ ]
}
+
}
@@ -0,0 +1,5 @@
+define ['cs!model/news'], (News) ->
+ class NewsCollection extends Backbone.Collection
+ model: News
+ return NewsCollection
+
@@ -0,0 +1,17 @@
+define ['cs!widget'], (Widget) ->
+ class NewsListWidget extends Widget
+ subscribed_channels: ['/news']
+ template_name: 'templates/news_list_widget.hjs'
+
+ get_news: (params) =>
+ ###
+ This method will be called whenever there are changes
+ to the /news channel. Changes can be of multiple types,
+ as this data channel is actually a Backbone Collection.
+ (There is another type of channel as well, which can store raw
+ JSON data).
+ ###
+ @renderLayout({"news" : params.collection.models})
+
+ return NewsListWidget
+
@@ -0,0 +1,4 @@
+define [], () ->
+ class News extends Backbone.Model
+ return News
+
@@ -0,0 +1,13 @@
+define ['cs!controller'], (Controller) ->
+ class NewsListController extends Controller
+ action: =>
+ [news] = Utils.newDataChannels({'/news': {}})
+
+ params =
+ news_list_params:
+ 'channels':
+ '/news': news
+
+ @renderLayout(params)
+
+ return NewsListController
@@ -10,4 +10,4 @@ define ['cs!widget'], (Widget) ->
###
@renderLayout({"task" : params.model.get('task')})
- return TodoWidget
+ return TodoWidget
@@ -0,0 +1,2 @@
+<h2>News</h2>
+<a href="/">Back</a>
View
@@ -0,0 +1 @@
+<div class="uberwidget" data-widget="news_list_widget" data-params="{{news_list_params}}"></div>
View
@@ -1,2 +1,4 @@
<div class="uberwidget" data-widget="todo_add_widget" data-params="{{todo_add_params}}"></div>
-<div class="uberwidget" data-widget="todo_list_widget" data-params="{{todo_list_params}}"></div>
+<div class="uberwidget" data-widget="todo_list_widget" data-params="{{todo_list_params}}"></div>
+
+<a href='#news'>News</a>
@@ -1 +1 @@
-<span>{{task}}</span>
+<span>{{task}}</span>

0 comments on commit 7a16cc7

Please sign in to comment.