TAILIEUCHUNG - Phát triển Javascript - part 40

Tham khảo tài liệu 'phát triển javascript - part 40', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | Domain Model and Storage 363 The test exposes our cheat so we need to find a better way to generate ids. Listing uses a simple variable that is incremented each time a message is added. Listing Assigning unique integer ids var id 0 var chatRoom addMessage function user message callback . if err data id id user user message message . Tests are passing again. You might worry that we re not actually storing the message anywhere. That is a problem but it s not currently being addressed by the test case. To do so we must start testing message retrieval. Fetching Messages In the next chapter we will interface with the chat backend using the cometClient from Chapter 13 Streaming Data with Ajax and Comet. This means that chatRoom needs some way to retrieve all messages since some token. We ll add a getMessagesSince method that accepts an id and yields an array of messages to the callback. The getMe ssagesSince Method The initial test for this method in Listing adds two messages then tries to retrieve all messages since the id of the first. This way we don t program any assumptions about how the ids are generated into the tests. Listing Testing message retrieval testCase exports should get messages since given id function test var room chatRoom var user cjno Download from 364 Server-Side JavaScript with user msg function e first user msg2 function e second function e msgs msgs msgs second The test fails in the face of a missing getMessagesSince. Listing adds an empty method that simply calls the callback without arguments. Listing Adding getMessagesSince var chatRoom addMessage function user message callback . getMessagesSince function id callback callback Because addMessage isn t really storing the messages anywhere there s no way for getMessagesSince to .

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.