Skip to content

Commit bb9c3fa

Browse files
committed
update core.
1 parent 32135fa commit bb9c3fa

File tree

4 files changed

+178
-9
lines changed

4 files changed

+178
-9
lines changed

rabbit.el

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@
55
(let ((__dir__ (file-name-directory load-file-name)))
66
(cask-initialize __dir__)
77
(add-to-list 'load-path (concat __dir__ "src"))
8+
(require 'rabbit-core))
89

9-
;; register config
10-
(require 'rabbit-util)
11-
(rabbit/store-register :__dir__ __dir__)
12-
)
1310

14-
(require 'rabbit-core)

snippets/emacs-lisp-mode/rabbitmacs-init-file

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,14 @@
3232

3333
;;; Code:
3434

35-
(provide '${2:`(rabbit/buffer-name-base)`})
36-
3735
(defun ${3:`(rabbit/replace-import-name)`} ()
3836
"Main call."
3937
$0
4038
)
4139

40+
41+
(provide '${2:`(rabbit/buffer-name-base)`})
42+
4243
;; Local Variables:
4344
;; coding: utf-8
4445
;; End:

src/rabbit-core.el

Lines changed: 134 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,139 @@
1-
(provide 'rabbit-core)
1+
;;; rabbit-core.el --- core.rabbitmacs -*- lexical-binding:t -*-
2+
3+
;; Copyright (C) 2017 Rabbit
4+
5+
;; Maintainer: Rabbit <yfhj1990@hotmail.com>
6+
;; Package: rabbitmacs
7+
8+
;; MIT License
9+
10+
;; Permission is hereby granted, free of charge, to any person obtaining a copy
11+
;; of this software and associated documentation files (the "Software"), to deal
12+
;; in the Software without restriction, including without limitation the rights
13+
;; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14+
;; copies of the Software, and to permit persons to whom the Software is
15+
;; furnished to do so, subject to the following conditions:
16+
17+
;; The above copyright notice and this permission notice shall be included in all
18+
;; copies or substantial portions of the Software.
19+
20+
;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21+
;; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22+
;; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23+
;; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24+
;; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25+
;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26+
;; SOFTWARE.
27+
28+
;;; Code:
229

330
(require 'rabbit-util)
431

5-
(import 'rabbit-default)
32+
(import rabbit-default)
633
(import 'rabbit-face)
734
(import 'rabbit-edit)
35+
36+
(defvar rabbit/store '() "rabbitmacs store.")
37+
38+
39+
(defun rabbit/store-creator (update)
40+
""
41+
42+
(let* ((curr-listener '())
43+
(curr-modal '())
44+
(curr-update update)
45+
(next-listener curr-listener)
46+
(is-dispatching nil)
47+
48+
(make-imuttable-listener (lambda (fn)
49+
(when (eq next-listener curr-listener)
50+
(setq next-listener (-slice curr-listener 0)))
51+
(funcall fn)
52+
))
53+
(get-modal (lambda () curr-modal))
54+
55+
(subscribe (lambda (listener)
56+
(let ((is-subscribe t))
57+
58+
(make-imuttable-listener
59+
(lambda ()
60+
(push listener curr-listener)))
61+
62+
(lambda ()
63+
"Unsubscribe."
64+
(when is-subscribe
65+
(setq is-subscribe nil)
66+
(make-imuttable-listener
67+
(lambda ()
68+
(let (idx (-elem-index listener curr-listener))
69+
(-remove-at idx curr-listener)))))))))
70+
71+
(dispatch (lambda (msg)
72+
"Dispatch msg"
73+
74+
(print curr-update)
75+
76+
(unless is-dispatching
77+
(setq is-dispatching (not is-dispatching))
78+
(setq curr-modal (curr-update curr-modal msg))
79+
(setq is-dispatching (not is-dispatching))
80+
81+
;; fire listeners
82+
(-each curr-listener
83+
(lambda (listener)
84+
(funcall listener))))))
85+
)
86+
87+
88+
(setq rabbit/store (list :type :store
89+
:dispatch 'dispatch
90+
:subscribe 'subscribe
91+
:get-modal 'get-modal
92+
))))
93+
94+
(rabbit/store-creator (lambda (state action)
95+
(print action)
96+
state))
97+
98+
(funcall (plist-get rabbit/store :dispatch) 123)
99+
100+
(defun rabbit/listener-creator (fn)
101+
"Create listener."
102+
(list :type :listener
103+
:call fn))
104+
105+
106+
(defun defmodal (body)
107+
""
108+
(let* ((model rabbit/modal)
109+
(key (intern (buffer-name))))
110+
(plist-put rabbit/modal key body)))
111+
112+
(defmodal '((a . 1) (b . 2)))
113+
114+
(defun rabbit/dispatch (store)
115+
"dispatch a action."
116+
(lambda (action)
117+
118+
)
119+
)
120+
121+
(rabbit/listener-creator
122+
(lambda (x) (print x) ))
123+
124+
125+
(defun rabbit/subscription ()
126+
""
127+
128+
)
129+
130+
131+
132+
133+
134+
(provide 'rabbit-core)
135+
136+
;; Local Variables:
137+
;; coding: utf-8
138+
;; End:
139+
;;; rabbit-core.el ends here

src/rabbit-welcome.el

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
;;; rabbit-welcome.el --- welcome -*- lexical-binding:t -*-
2+
3+
;; Copyright (C) 2017 Rabbit
4+
5+
;; Maintainer: Rabbit <yfhj1990@hotmail.com>
6+
;; Package: rabbitmacs
7+
8+
;; MIT License
9+
10+
;; Permission is hereby granted, free of charge, to any person obtaining a copy
11+
;; of this software and associated documentation files (the "Software"), to deal
12+
;; in the Software without restriction, including without limitation the rights
13+
;; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14+
;; copies of the Software, and to permit persons to whom the Software is
15+
;; furnished to do so, subject to the following conditions:
16+
17+
;; The above copyright notice and this permission notice shall be included in all
18+
;; copies or substantial portions of the Software.
19+
20+
;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21+
;; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22+
;; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23+
;; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24+
;; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25+
;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26+
;; SOFTWARE.
27+
28+
;;; Code:
29+
30+
(provide 'rabbit-welcome)
31+
32+
(defun rabbit/welcome ()
33+
"Main call."
34+
35+
)
36+
37+
;; Local Variables:
38+
;; coding: utf-8
39+
;; End:
40+
;;; rabbit-welcome.el ends here

0 commit comments

Comments
 (0)