lib/lookbook/engine.rb in lookbook-2.0.0.beta.1 vs lib/lookbook/engine.rb in lookbook-2.0.0.beta.2

- old
+ new

@@ -80,10 +80,14 @@ def auto_refresh? reloading? && runtime_context.web? && FileWatcher.evented? end + def preview_embeds_allowed? + opts.preview_embeds.enabled == true && opts.preview_embeds.policy != "DENY" + end + def websocket @_websocket ||= auto_refresh? ? Websocket.new(mount_path, logger: Lookbook.logger) : NullWebsocket.new end def runtime_context @@ -148,11 +152,11 @@ end def preview_watch_paths return @_preview_watch_paths if @_preview_watch_paths - paths = [*opts.preview_paths, opts.components_path, *opts.listen_paths, *view_paths].uniq + paths = [*opts.preview_paths, *opts.component_paths, *opts.listen_paths, *view_paths].uniq @_preview_watch_paths ||= PathUtils.normalize_paths(paths) end def pages @_pages ||= PageCollection.new @@ -171,15 +175,17 @@ def load_previews(changes = nil) changed_files = [*changes[:added], *changes[:modified]] if changes parser.parse(changed_files) do |code_objects| previews.load(code_objects.all(:class), changes) + mark_changed end end def load_pages(changes = nil) pages.load(Engine.page_paths, changes) + mark_changed end def notify_clients(changes = nil) return unless changes.present? @@ -189,9 +195,18 @@ def files_changed(modified, added, removed) changes = {modified: modified, added: added, removed: removed} reloaders.register_changes(changes) notify_clients(changes) + end + + def mark_changed + @_last_changed = (Time.now.to_f * 1000).to_i + end + + def last_changed + mark_changed unless @_last_changed + @_last_changed end end at_exit do Engine.run_hooks(:before_exit)