@rip-lang/server 1.2.4 → 1.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/server.rip +11 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rip-lang/server",
3
- "version": "1.2.4",
3
+ "version": "1.2.5",
4
4
  "description": "Pure Rip application server — multi-worker, hot reload, HTTPS, mDNS",
5
5
  "type": "module",
6
6
  "main": "server.rip",
package/server.rip CHANGED
@@ -576,17 +576,23 @@ class Manager
576
576
  watchDirs: (prefix, dirs) ->
577
577
  return if @appWatchers.has(prefix)
578
578
  timer = null
579
+ pending = null
579
580
  watchers = []
580
- broadcast = =>
581
+ broadcast = (type = 'reload') =>
582
+ pending = if type is 'reload' or pending is 'reload' then 'reload' else type
581
583
  clearTimeout(timer) if timer
582
584
  timer = setTimeout =>
583
585
  timer = null
584
- @server?.broadcastChange(prefix)
586
+ @server?.broadcastChange(prefix, pending)
587
+ pending = null
585
588
  , 100
586
589
  for dir in dirs
587
590
  try
588
591
  w = watch dir, { recursive: true }, (event, filename) ->
589
- broadcast() if filename?.endsWith('.rip')
592
+ if filename?.endsWith('.rip')
593
+ broadcast('reload')
594
+ else if filename?.endsWith('.css')
595
+ broadcast('css')
590
596
  watchers.push(w)
591
597
  catch e
592
598
  console.warn "rip-server: watch failed for #{dir}: #{e.message}"
@@ -894,12 +900,12 @@ class Server
894
900
  'Cache-Control': 'no-cache'
895
901
  'Connection': 'keep-alive'
896
902
 
897
- broadcastChange: (prefix) ->
903
+ broadcastChange: (prefix, type = 'reload') ->
898
904
  group = @watchGroups.get(prefix)
899
905
  return unless group
900
906
  dead = []
901
907
  for client as group.sseClients
902
- try client.send('reload')
908
+ try client.send(type)
903
909
  catch then dead.push(client)
904
910
  group.sseClients.delete(c) for c in dead
905
911